class Post
has_many :commments
end
class Comment
belongs_to :post
end
通过属性顺序的ActiveRecord对象我希望显示的post
创建(submitted_at
)的日期排序的posts
列表。我还想要一些post
xyz出现在顶部,如果它有一些新的评论发布,但尚未由主持人审查。我们将在注释水平boolean
属性/场(主持= 1/0)Rails的:下的has_many关系
确定这个我试过
Posts.join(:comments)
.distinct
.order("submitted_at DESC, comments.moderated")
,但这不包括那些没有comments
和预期结果进行排序的职位。我相信我们可以在ruby层面上做到这一点,但是寻找一种使用AR来做到这一点的方法。
如何使用“包括”,而不是“加入” – chaitanya
可能是这将有助于http://stackoverflow.com/questions/3245201/left-outer-joins-in-rails-3 – chaitanya