Searchkick joins between models

2.1k Views Asked by At

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.

2

There are 2 best solutions below

2
On BEST ANSWER

eager loading example from gem reference

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

for your code above

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

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'}