has_many :通过两个值的查询
假设我有:
class Post
has_many :tags, :through => :taggings
has_many :taggings
end
请注意,没有 :include。现在假设我想检索同一查询中的所有标记和标签。我怎么能这么做呢?
我正在寻找类似的东西:
taggings = post.taggings(:include => tags) # doesn't work
我可以进行自定义查询或使用 :include 添加第三个关联到 Post,但这两种感觉都不对。
Let's say I have:
class Post
has_many :tags, :through => :taggings
has_many :taggings
end
Notice there's no :include. Now say I want to retrieve all taggings and tags in the same query. How could I do that?
I'm looking for something like:
taggings = post.taggings(:include => tags) # doesn't work
I could make a custom query or add a third association to Post with an :include, but neither feels right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以像使用模型类一样在关联代理上使用
includes
:I think you can use
includes
on the association proxy as you would with the model class: