Rails 3 finding parents which have no child

前端 未结 3 820
遇见更好的自我
遇见更好的自我 2020-12-06 18:57

In a one to many relationship with no counter cache how can I find parents with no child?

user.rb

has_many :pages

page.rb



        
3条回答
  •  爱一瞬间的悲伤
    2020-12-06 19:22

    I believe something like

     User.all(:joins => :comments, :select => "users.*, count(comments.id) as comments_count", :group => "users.id")
    

    might work also...

提交回复
热议问题