I have the following model associations:
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
I gave with a set to part_of_speech_idssay [1,2,3]. With these associations, I have to find all the words that have all these part_of_speeches in it. The word with part_of_speech_ids[1,2,3,4] should be displayed, but not the word only with [1,2].
A query with IN will not produce the correct result because it is performing an OR operation . I want something that does AND for array elements.
Please, help.
source
share