【发布时间】:2016-08-24 08:59:26
【问题描述】:
我有以下模型关联:
class PartOfSpeech < ActiveRecord::Base
has_many :part_of_speech_words
has_many :words, through: :part_of_speech_words
end
class Word < ActiveRecord::Base
has_many :part_of_speech_words
has_many :part_of_speeches, through: :part_of_speech_words
end
class PartOfSpeechWord < ActiveRecord::Base
belongs_to :part_of_speech
belongs_to :word
end
我给了一组part_of_speech_ids 说[1,2,3]。有了这些关联,我必须找到包含所有这些 part_of_speeches 的所有单词。必须显示带有part_of_speech_ids [1,2,3,4] 的单词,但不能出现仅带有 [1,2] 的单词。
使用 IN 查询不会给出正确的结果,因为它执行 OR 操作。我想要对数组元素执行 AND 的东西。
请帮忙。
【问题讨论】:
标签: ruby-on-rails postgresql activerecord