Stale ActiveRecord Object

In a non-rails application, I am using AR as my ORM.

I am using an AR object in multiple places in my application. At one
point, I update the AR object and commit the changes to the db.

Later, I access that AR object and I need to check the value of an
attribute. While this attribute has been updated in mysql, the AR
object shows the old value.

Is this an issue of poor design on my part? Should I take a different
approach or is there some way to update/refresh an AR object?

Thanks,

John

John H. wrote:

Is this an issue of poor design on my part? Should I take a different
approach or is there some way to update/refresh an AR object?

Call #reload on the object.

If you have more than one thread/process accessing the database then you
still have a race condition…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs