I'm trying to use the :conditions option on the activerecord find. For a
simple query such as "SELECT * FROM products WHERE name LIKE
'%#{name}%'" it's obviously
:conditions => ["name LIKE ?", "'%#{name}%'"]
However, I have associated models, so for example I might have
product.location.address to access in the view, but only a location_id
field in the products table.
To find a product based on location address in MySQL (say, from a search
box saved in variable address), I might perform this query:
"SELECT * FROM products WHERE location_id in (SELECT distinct id FROM
locations WHERE address LIKE '%#{address}%')"
So, I have nested select statements. How can I perform this query inside
the :conditions option? Is there a simpler and secure way to accomplish
what I need?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---