Jeremy B
Jeremy B

Reputation: 911

Rails Joins and Like?

I am trying to use joins in rails to retrieve some info base on a search field but I cannot seem to find the good syntax, I have two table savings and product and saving are saving for a product. What I want is to find a saving based on the name of the product I found that this work : Saving.all(:joins => :product, :conditions => { :products => { :title => 'Title Name' } }) It retrieve the saving corresponding to the product named Title Name.

Now how can I change that to find the savings where product title contains params[:title] ?

Thanks,

Upvotes: 1

Views: 2463

Answers (2)

Jeremy B
Jeremy B

Reputation: 911

Saving.joins{product}.where{(savings.products.title =~ my{"%#{params[:term]}%"} } with squeel

Upvotes: 1

aromero
aromero

Reputation: 25761

Saving.joins(:product).where('products.title like ?', "%#{params[:title]}%")

Upvotes: 2

Related Questions