How can I find records by “count” of association using rails and mongoid?

前端 未结 3 708
情书的邮戳
情书的邮戳 2021-02-04 16:43

With these models:

class Week
  has_many :proofs
end
class Proof
  belongs_to :week
end

I want to do something like:

Week.where         


        
3条回答
  •  青春惊慌失措
    2021-02-04 17:24

    Pardon me if I'm way off - but would you be able to use a simple counter_cache in the weeks table? Then you could do something like week.proofs_count.

提交回复
热议问题