Get multiple records with one query

Posted by Lewy on Stack Overflow See other posts from Stack Overflow or by Lewy
Published on 2010-12-26T13:46:22Z Indexed on 2010/12/26 13:54 UTC
Read the original article Hit count: 340

Filed under:
|

User table:

name lastname

Bob Presley
Jamie Cox
Lucy Bush

Find users

q = Query.new("Bob Presley, Cox, Lucy")
q.find_users => {0=>{:name=>"Bob", :lastname=>"Presley"}, 1=>{:lastname=>"Cox"}, 2=>{:name=>"Lucy"}}

Question:

I've got hash with few names and lastnames. I need to build Activerecord query to fetch all users from that hash.

I can do

object = []
hash = q.find_users
hash.each do |data|
 #check if data[:lastname] and data[:name] exist
 # object << User.where(:name => ..., :lastname => ...)
end

But I think it is higly inefficient. How should I do this ?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord