ruby on rails 3 - Possible to use ActiveRecord methods against AR collections? -


i able pull records db:

 u = user.all 

and once loaded able apply ar methods resulting collection:

 u.first 

is possible in rails?

once query database, results become array instead of activerecord::relation. (though #first still work fine, since it's method exists on array).

if need starting point build activerecord::relation though, can use scoped:

# doesn't execute query yet u = user.scoped # executes query similar select * users limit 1 u.first 

note in rails 4.0, #all same thing #scoped (whereas in rails 3, returns array).


Comments