【发布时间】:2015-01-30 22:33:33
【问题描述】:
我有两个模型 - Blog 和 BlogTag。博客 has_many :blog_tags 和 BlogTag belongs_to :blog:
blog.rb
has_many :blog_tags
blog_Tag.rb
belongs_to :blog
我想查询数据库以根据用户在表单字段中输入的内容选择所有在 blog_tags 表中具有匹配标签的博客。像这样的:
Blog.where(blog_tags contain [array of tags])
有没有办法用 ActiveRecord 做到这一点?
【问题讨论】:
标签: ruby-on-rails activerecord