Gee-off wrote:
> I'm trying to get the following statement to work using variable
> substitution (it works if hard-code the where (med_type) param in the
> inner SQL statement):
>
> med_type = 'game'
> @mediaformats = MediaFormat.find_by_sql("select * from media_formats
> where media_formats.media_type_id = (select media_type_id from
> media_types where media_type = ?, :med_type) order by description")
>
Well, you're trying do string interpolation wrong, as Philip pointed
out. But there's no point using find_by_sql. Assuming you have your
associations set up properly, all you need is
@mediaformats = MediaType.find_by_name(med_type).media_formats .
[...]
>
> Any help appreciated - I'm using find_by_sql only because I'm more
> comfortable with SQL than Rails queries.
That is a terrible reason to use find_by_sql. If you're going to use
Rails, take the time to actually learn to *use* it. If not, do yourself
a favor and remove it from your project. There is no point is using a
framework if you're just going to ignore it.
>
> geoff
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
--
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
-~----------~----~----~----~------~----~------~--~---