q1 = Question.find(1)
q2 = Question.find(1)
Now, we find q1.id != q2.id.
It appears the two aliases are not kept in sync:
q1.name => ‘old name’
q2.name = ‘new name’
q2.save!
q1.name => ‘old name’
q2.name => ‘new name’
q1.reload
q1.name => ‘new name’
Even worse, is this fun:
q1.destroy
q2.name = ‘third name’
q2.save!
That actually runs; ActiveRecord happily updates all 0 rows that match
(let’s hope IDs can never be re-used, or that could have just updated
the wrong row)
Finally,
q2.reload
ActiveRecord::RecordNotFound: Couldn’t find Question with ID=1
Why does ActiveRecord return two objects both representing a single row
in the database?