ruby 如何将ActiveRecord范围委托给Query对象

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 如何将ActiveRecord范围委托给Query对象相关的知识,希望对你有一定的参考价值。

module Cards
  class BlackListedQuery
    class << self
      delegate :call, to: :new
    end

    def initialize(relation = Card.unscoped)
      @relation = relation
    end

    def call
      @relation.where "cards.black_listed_at IS NOT NULL"
    end
  end
end
class Card
  scope :black_listed, Cards::BlackListedQuery
end

以上是关于ruby 如何将ActiveRecord范围委托给Query对象的主要内容,如果未能解决你的问题,请参考以下文章