ruby - ActiveRecord objects - querying retrieved records -
this puzzling me.
i have:
person = person.find_or_create_by(user_id: some_id) previous_person = person.where('user_id < ?' some_id).limit(1).order('user_id desc') binding.pry
in pry do:
person.user_id => 12 previous_person.user_id nomethoderror: undefined method `user_id' #<activerecord::relation::activerecord_relation_person:0x007fdd24d635b8>
why can't access user_id previous_person?
(apologies typos - wasn't direct copy , paste)
doh. can' believe fell again!
of course, person.where returns array.
the correct code previous_person = person.where('user_id < ?' some_id).order('user_id desc').first
Comments
Post a Comment