【发布时间】:2015-09-09 06:52:24
【问题描述】:
ActiveRecord querying 有一个关于在急加载关联上指定条件的部分。具体来说,第 13.2 节。
据此,我可以做到以下几点:
Article.includes(:comments).where(comments: { visible: true })
如果我想做这样的事情怎么办...
Article.where(param: "this").includes(user: [:comments]).where(comments: { text: "wow" })
当然,上述方法不起作用,我希望能够通过一些查询来实现。
就目前而言,在我的查询之后,我做了一个articles[3].user.comments.select { |comment| comment.text == "wow" }
以上都达到了吗?
【问题讨论】:
-
你可以试试这个
Article.includes(user: [:comments]).where(id: 3, comments: { text: "wow" })
标签: ruby-on-rails ruby-on-rails-4 rails-activerecord eager-loading