Is it:
u = User.find_by_email("me@myplace.com")
or:
u = User.where(:email => "me@myplace.com").first
I think I read that conditions are being phased out in 3.1.
I know you want to stick with AREL on retrieving multiple objects, because it figures out when to actually do the query (like if you’re iterating through a collection). But I don’t know what the convention is for grabbing singles.
I use both interchangeably.
I haven’t read anything about the
find_bymethods being deprecated, but if your concern is that they will be, then use the second approach. You’re only other option is to calllast. You could also callallbut that would return the object in an array.Read section 1.1 Retrieving a Single Object of the Edge Guides article Active Record Querying for more information.