如何获取所有具有子对象的对象

How to get all objects that have child objects

我的帖子模型具有称为反馈、众筹和想法的嵌套属性。

我想编写一个方法来显示所有有反馈的帖子、所有有众筹的帖子和所有有想法的帖子。我该如何做到这一点?在我看来是这样的:

Post.find(feedbacks.present?)

Post.all where (feedbacks.present)

我会这样做:

Post.includes(:feedbacks).where.not(feedbacks: { id: nil })

或者:

Post.joins(:feedbacks)