views:

17

answers:

1
u = User.where("name = ?", "mateusz").limit(1)
u.class
=> ActiveRecord::Relation

So I cant do smth like u.email and so on. .find does right, returns User object. Is there any chance to get an User object from ActiveRecord::Relation object?

+3  A: 

You should call first or last on the ActiveRecord::Relation object:

u = User.where("name = ?", "mateusz").first
neutrino
thanks this helped a lot. question though, so where assumes you always get multiple rows with that right? that's why you need the first?
corroded