I have these two tables:
product has_one address
address belongs_to product
When I want to find a product from one city, I do:
Product.all.joins(:address).where(addresses: {city: @city})
When I want to to find all cities with case insensitive is
Address.all.where('lower(city) like ?', @city.downcase)
But now I want a record from another table with case insensitive combined. How can I do ?
I tried some ways and nothing:
Product.all.joins(:address).where(addresses: {"lower(city) like ?", @city.downcase})
gives the error:
SyntaxError: unexpected '}', expecting end-of-input
...ower(city) like ?", "new york"})
...
and the other way:
Product.all.joins(:address).where(addresses: {"lower(city) like ?": @city.downcase})
gives nothing:
#<Product::ActiveRecord_Relation:0x3fb3fc142900>
Obs: I created another question because the old one was wrongly marked as duplicated.