Strange behaviour in ActiveRecord finder while using SQL condition IN?

The problem is that the literal is being passed into the SQL statement as a single literal InboxMessage. Find(:all, :conditions => "user_id IN (?)", "0,4") becomes Select ... WHERE (user_id IN ('4,0')) Try using two substitutions and it will work as you expect InboxMessage. Find(:all, :conditions => "user_id IN (?,?)", 0,4) becomes Select ... WHERE (user_id IN (4,0)) You can see what the actual SQL statement is by looking at the log in development mode.

The problem is that the literal is being passed into the SQL statement as a single literal. InboxMessage. Find(:all, :conditions => "user_id IN (?)", "0,4") becomes Select ... WHERE (user_id IN ('4,0')) Try using two substitutions and it will work as you expect InboxMessage.

Find(:all, :conditions => "user_id IN (?,? )", 0,4) becomes Select ... WHERE (user_id IN (4,0)) You can see what the actual SQL statement is by looking at the log in development mode.

I think you are right. Confusion was due to the fact that I got the expected results when I changed the bind parameter order. I managed to see the SQL and it is erroneous(as you noted).(PS: I used the "SQL_DISPLAY":github.Com/radar/sql_display plugin to list the SQL) – KandadaBoggu Feb 10 '10 at 4:13.

This is a different form which I prefer to use because I find it more readable: InboxMessage. Find_all_by_user_id(0,4).

I have multiple parameters in my find call. I simplified the sample code for easier read. – KandadaBoggu Feb 10 '10 at 4:00.

I think you're thinking of this backwards. Search those tables through the user object that you have, ensuring that they are already associated in ActiveRecord. That will return all magazines that have a user_id equal to the user's ID.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions