I`veを掻き回す検索がいずれかを持っているレコードを検索しようとして掻き回すと行為-AS-タグ付けできるオン
class Film < ActiveRecord::Base
attr_accessible :mood_list, :genre_list, :tag_list, :country_list
acts_as_taggable_on :countries, :genres, :moods, :tags
end
I`mに作用する-AS-タグ付けできるが、使用して、いくつかの分類法でモデルを得た課題気分の、そして正確に一致する国。しかし、私は一致するレコードを持っているのに対し、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
何も返されません!しかし、私は間違いなく1つを持っています:
>> 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'))
助けてください!
UPDATE:1/11/2013 問題は、ransack述語の正しい適用にあるべきです。 実際に解決されていないいくつかの関連する質問があります。それが問題のように見える Rails, Ransack: How to search HABTM relationship for "all" matches instead of "any"
Convert ActiveRecord habtm query to Arel
UPDATE はhttps://github.com/ernie/ransack/issues/164