Ruby 如何在Arel中混合/引用/调用自定义ActiveRecord方法
我有一个模型,其中我实现了一个返回一组记录的方法。有可能在Arel中介绍他们吗Ruby 如何在Arel中混合/引用/调用自定义ActiveRecord方法,ruby,activerecord,arel,Ruby,Activerecord,Arel,我有一个模型,其中我实现了一个返回一组记录的方法。有可能在Arel中介绍他们吗 class A < ActiveRecord::Base #associations here def self.mymeth #return a set of records based on a query B.select(col).joins(:cs).where(some_condition) end end class B < ActiveRecord::Ba
class A < ActiveRecord::Base
#associations here
def self.mymeth
#return a set of records based on a query
B.select(col).joins(:cs).where(some_condition)
end
end
class B < ActiveRecord::Base
#associations here
end
class C < ActiveRecord::Base
#associations here
end
你不是在找我吗
调用时,将在范围中添加的所有SQL条件都将自动添加到查询中
A.joins(:mymeth).where(condition).count
class A < ActiveRecord::Base
scope :myscope, lambda { joins(:b).where(column: true) }
end
A.mymeth.where(col: false)