这是一个关于IT技术的翻译问题。要求翻译一段关于“course”和“tags”的内容,需要用到“has_many”和“has_and_belongs_to”两个技术。现在有两个标签的ID,分别是1和2,请问如何找到所有同时拥有这两个标签的课程。
Course.joins(:tags).where("tags.id IN (?)" [1, 2])
这个查询语句只会返回拥有其中一个标签的记录,而不是我想要的结果。
# app/models/course.rb
has_and_belongs_to_many :tags
# app/models/tag.rb
has_and_belongs_to_many :courses
tags.id = 1
å’Œtags.id = 2
的记录。 - PavanALL
运算符。 - Vapire