मैं `veलूटना और कृत्यों के रूप में taggable-ऑन मुद्दों
पर कार्य करता है के रूप में taggable का इस्तेमाल करने वाली कई taxonomies के साथ एक मॉडल मिल गयाclass Film < ActiveRecord::Base
attr_accessible :mood_list, :genre_list, :tag_list, :country_list
acts_as_taggable_on :countries, :genres, :moods, :tags
end
मैं` लूटना खोज रिकॉर्ड है कि किसी भी लगता है बनाने की कोशिश कर मूड, और बिल्कुल मिलान करने वाला देश। लेकिन यह 0 रिकॉर्ड को बरकरार रखता है, जबकि मेरे पास एक मिलान रिकॉर्ड है, देखें:
Film.search({:moods_name_in=>['happy', 'snooze']}).result.count => 2
Film.search({:countries_name_eq=>'USA'}).result.count => 2
Film.search({:moods_name_in=>['happy', 'snooze'], :countries_name_eq=>'USA'}).result.count => 0
यह कुछ भी नहीं देता !!! लेकिन मेरे पास निश्चित रूप से एक है:
>> f.countries
[#<ActsAsTaggableOn::Tag id: 13, name: "USA">]
>> f.moods
[#<ActsAsTaggableOn::Tag id: 17, name: "active">, #<ActsAsTaggableOn::Tag id: 16, name: "psyched">, #<ActsAsTaggableOn::Tag id: 15, name: "happy">]
The SQL generated is:
(3.2ms) SELECT COUNT(DISTINCT "films"."id") FROM "films" LEFT OUTER JOIN "taggings" ON "taggings"."taggable_id" = "films"."id" AND taggings.context = ('moods') AND "taggings"."taggable_type" = 'Film' LEFT OUTER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" LEFT OUTER JOIN "taggings" "country_taggings_films_join" ON "country_taggings_films_join"."taggable_id" = "films"."id" AND taggings.context = ('countries') AND "country_taggings_films_join"."taggable_type" = 'Film' LEFT OUTER JOIN "tags" "countries_films" ON "countries_films"."id" = "country_taggings_films_join"."tag_id" WHERE (("tags"."name" IN ('happy', 'snooze') AND "countries_films"."name" = 'USA'))
कोई मदद कृपया!
अद्यतन: 1/11/2013 समस्या सही आवेदन करने वाले रैनैक भविष्यवाणी में झूठ बोलनी चाहिए। कई संबंधित प्रश्न हैं जो वास्तव में हल नहीं होते हैं। Rails, Ransack: How to search HABTM relationship for "all" matches instead of "any"
Convert ActiveRecord habtm query to Arel
अद्यतन यह मुद्दा की तरह लग रहा has_and_belongs_to_many के लिए न सुलझा हुआ घटना है https://github.com/ernie/ransack/issues/164