Forum: Ruby on Rails MySQL Where conditions automatic formatting

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jonathon Paul M. (Guest)
on 2007-06-26 22:50
(Received via mailing list)
Hi,

I'm having a problem with the automatic formatting of my mysql query.

My code is this:

Tablename.find(:all, :conditions => {:id => list})

Where list is a list of id's (8,9,10)

The problem is that the query is automatically formatted to this:

SELECT * FROM Tablename WHERE (id in ('8,7,9'))

I need this query to run without the extra single quotes to work
properly.

ie: SELECT * FROM identifications WHERE (id in (8,7,9))

How do I go about this?

Thanks,

Jonathon
Bob S. (Guest)
on 2007-06-26 23:02
(Received via mailing list)
On 6/26/07, Jonathon Paul M. <removed_email_address@domain.invalid> wrote:
> The problem is that the query is automatically formatted to this:
>
> SELECT * FROM Tablename WHERE (id in ('8,7,9'))
>
> I need this query to run without the extra single quotes to work properly.
>
> ie: SELECT * FROM identifications WHERE (id in (8,7,9))
>
> How do I go about this?

list needs to be an Array, not a String:

  list = [8,7,9]             # array of values

It looks like you have list as a string "8,7,9", which is a single
value.
Jonathon Paul M. (Guest)
on 2007-06-26 23:13
(Received via mailing list)
Thanks
This topic is locked and can not be replied to.