rails3 scope for count of children in has_many relationship

后端 未结 4 1704
感动是毒
感动是毒 2021-02-14 03:08

trying to do a scope in rails3.

:book has_many :chapters 

I want scope :long to return books with > 10 chapters.

How best to structure

4条回答
  •  误落风尘
    2021-02-14 04:02

    In rails 4.0 this version works. You have to count() in the having clause. It seems that having clause doesn't see 'as n_chapters'.

提交回复
热议问题