Answer the question
In order to leave comments, you need to log in
How can I use the Tire gem to search by the fields of a linked table?
Hello.
There is a model with the following code:
mapping do
indexes :id, type: 'integer'
indexes :name, type: 'string'
indexes :address, type: 'string'
indexes :offices_pub_count, type: 'integer'
indexes :offices do
indexes :retail, type: 'boolean'
end
end
def as_indexed_json(options={})
to_json(methods: [:offices_pub_count],
include: { offices: { only: [:text,:desc,:floor,:inner_info,:decoration,:fire_safety,:air_conditioning,:parking,:planning,
:commercial_terms,:operation_cost_id, :retail] } }
def offices_pub_count
offices_pub.size
end
has_many :offices, :dependent => :destroy
has_many :offices_pub, class_name: 'Office', foreign_key: 'business_center_id', conditions: {published: true}
BusinessCenter.search(:load => { :include => 'offices' }) do
query { string '*' }
filter :term, "offices.retail" => true
end
Answer the question
In order to leave comments, you need to log in
And this is not forgotten, as in the example?
class Chapter < ActiveRecord::Base
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Do not forget to automatically `touch` parent object from associations
belongs_to :book, touch: true
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question