String problem

Hi How to find the resut by passing string as parameters in clause of
mysql query

For example
arr = [‘t’,‘a’]
@user = User.find(:all,:conditions=>[“firstname IN(#{arr.join(’,’)})”])
it is executing like
select * from users where firstname IN(‘t,a’)
it returns 0 rows

Plz reply if anybody knows solution

Hi –

On Mon, 24 Nov 2008, Ganesh G. wrote:

Hi How to find the resut by passing string as parameters in clause of
mysql query

For example
arr = [‘t’,‘a’]
@user = User.find(:all,:conditions=>[“firstname IN(#{arr.join(’,’)})”])
it is executing like
select * from users where firstname IN(‘t,a’)
it returns 0 rows

You’ll probably get more responses to ActiveRecord questions on the
Rails mailing lists. Meanwhile:

:conditions => [“firstname IN (?)”, arr]

David

Ganesh G. wrote:

Hi How to find the resut by passing string as parameters in clause of
mysql query

For example
arr = [‘t’,‘a’]
@user = User.find(:all,:conditions=>[“firstname IN(#{arr.join(‘,’)})”])

Docs: http://apidock.com/rails/ActiveRecord/Base/find/class

test666> arr = %w(a b)
=> [“a”, “b”]
test666> User.find(:all, :conditions => { :firstname => arr} )
User Load (26.0ms) SELECT * FROM users WHERE (users.firstname
IN (‘a’,‘b’))