I have models below:
class Location < ActiveRecord::Base has_many :location_items has_many :items, :through=>:location_items end class Item < ActiveRecord::Base has_many :location_items has_many :locations, :through=>:location_items end class LocationItem < ActiveRecord::Base belongs_to :item belongs_to :location end
In addition, I have a full-text search (from gem) for the item model, I can do Item.search ('keyword') - โsearchโ is the area provided by the gem to get all items with a keyword for description or description , the rank attribute has been added to the result element for relevance to the match
I also have a Geo search (from the gem) for a location model, I can do Location.near ('Toronto. ON', 100) --- "nearby" is the area provided by the gem to get all locations in 100 km from Toronto, in the place of the result the attribute "distance" is added for the distance from this location - Toronto in this example
So now I am trying to get a list of location_item objects that have a location corresponding to a specific location and an element matching a given keyword. For example, find location_item objects matching the โkeywordโ and within 100 km of Toronto.
How can I achieve this with query one ? and can also access distance and rank attributes through an associated element and location inside the location_item object.
It seems like I canโt focus the scope since they only work with Item and Location, not with LocationItem,
For example, the expression below will not work
LocationItem.joins (: elements, locations) .search ('keyword'). near ('Toronto, ON', 100)
Hopefully my description of what I'm trying to do makes sense. Do you have any ideas? Thank you very much!