Manipulating attributes between database retrieval and return from finder

Is there a way to manipulate the attributes of an ActiveRecord-based
model after it is retrieved from the database but before it is
returned from the finder?

I have tried defining an after_find callback method but was unable to
access attributes that come from the database from this method. I
tried accessing them using self.an_attribute and read_attribute but
both raised an attribute exception.

I am trying to execute an upgrade-in-place strategy. When I deploy the
latest version of my app one of the attributes on every existing
record of a particular table will no longer be usable until converted
to a new format. Rather than take the app down for 12 hours to upgrade
the existing data I thought it could be upgraded on-access.

Evan

On Jan 8, 4:06am, Evan [email protected] wrote:

Is there a way to manipulate the attributes of an ActiveRecord-based
model after it is retrieved from the database but before it is
returned from the finder?

I have tried defining an after_find callback method but was unable to
access attributes that come from the database from this method. I
tried accessing them using self.an_attribute and read_attribute but
both raised an attribute exception.

Can you show exactly what you did and exactly what happened ? I can’t
imagine why this wouldn’t work.

Fred

On 8 January 2011 04:06, Evan [email protected] wrote:

Is there a way to manipulate the attributes of an ActiveRecord-based
model after it is retrieved from the database but before it is
returned from the finder?

I have tried defining an after_find callback method but was unable to
access attributes that come from the database from this method. I
tried accessing them using self.an_attribute and read_attribute but
both raised an attribute exception.

I think that if you implemented after_find and did find all that it
would have to run through the whole set, so would presumably take 12
hours. Maybe you do not do a find all, or even a find many, in which
case it should be able to work.

I am trying to execute an upgrade-in-place strategy. When I deploy the
latest version of my app one of the attributes on every existing
record of a particular table will no longer be usable until converted
to a new format. Rather than take the app down for 12 hours to upgrade
the existing data I thought it could be upgraded on-access.

An alternative might be to do the test/upgrade in the access method(s)
for whatever attribute(s) are affected.

Colin