Get multiple records with one query
- by Lewy
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 ?