Rails 3 finding parents which have no child

前端 未结 3 825
遇见更好的自我
遇见更好的自我 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条回答
  •  猫巷女王i
    2020-12-06 19:45

    Try

    User.joins("left join pages on pages.user_id = users.id").where("pages.user_id is null")
    

提交回复
热议问题