Rails tire(elasticsearch) search through has_many association -


i have 2 associations

belongs_to :author has_many :favorites 

i'm wondering why example works:

tire.search(load: {include: [:author, :comments]}, page: params[:page], per_page: 8)   query { string params[:query], default_operator: "and" } if params[:query].present?   filter :term, author_id: ['111']   sort { :created_at, 'desc' } end 

and 1 doesnt:

tire.search(load: {include: [:author, :comments]}, page: params[:page], per_page: 8)   query { string params[:query], default_operator: "and" } if params[:query].present?   filter :term, favorite_ids: ['567']   sort { :created_at, 'desc' } end 

can me?

foreign keys stored in child table, rails joining of 2 tables you.

so in model, there attribute author_id because model belongs to author. foreign keys favorites relationship stored in favorites table. while can model.first.favorites , corresponding favorites, because of value stored in latter table.

model.first.author_id exists. model.first.favorite_ids not.

if want run search on favorites_ids, you're going need explicitly define in to_indexed_json method.

also, tire has been retired. should migrating elasticsearch-rails, or preferred gem, searchkick!


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -