【发布时间】:2013-10-23 02:03:38
【问题描述】:
我有以下模型关系:
class Author
has_many :posts
end
class Post
belongs_to :author
has_many :comments
end
class Comment
belongs_to :post
end
我有布尔列“活跃”的作者和“发布”的帖子。
我想找到 author.active: true 和 post.published: true 的所有 cmets
谁能帮帮我?我可以通过使用 join 语句(Post 模型中的此代码)从 Author.active: true 获取作者的所有帖子:
joins(:author).where(authors: {active: true})
但我似乎无法弄清楚如何获取 author.active: true 和 post.published: true 的所有 cmets。
【问题讨论】:
标签: ruby-on-rails activerecord