spacerobot
spacerobot

Reputation: 297

Searchkick joins between models

Using searchkick gem how would I translate this to the .search way? Or is it not doable?

@projects = Project.joins(:proj_status)

Just wasn't sure how to do joins.

Upvotes: 0

Views: 2270

Answers (2)

Dias
Dias

Reputation: 882

If you want to search for projects with status then you might need to do in the following way

in your project model where searchkick included try this

this is for indexing data I assume Project has name and id and its associated model proj_status has a title.You may change the values depend on your model attributes

def search_data
   id: id,
   name: name,
   status: proj_status.title        
end

After Project.reindex

Then you can query Project model with status like,

@projects = Product.search "you query if any", includes: [:proj_status], where: {status: 'open'}

Upvotes: 0

widjajayd
widjajayd

Reputation: 6253

eager loading example from gem reference

Product.search "milk", includes: [:brand, :stores]

for your code above

@projects = Product.search "milk", includes: [:proj_status]

Upvotes: 1

Related Questions