Model with not te be updated attributes?

Hi List,

I have a table that contains several fields that must be initialized
when first created, but may not be altered afterwards (when updating the
other fields) because they can be changed by external processes.

I noticed that the ActiveRecord update commands (even update_attribute)
only seem to work by loading the complete record, changing fields that
need to be changed and doing a full update of all (even unchanged)
fields. I know it is only a matter of milliseconds between read/update,
but I don’t like to take any unneeded risks.

I found a workaround by overriding update_attributes in my model as
follows:

def update_attributes(attributes)
@attributes.delete(‘fieldthatshouldnotbechanged1’)
@attributes.delete(‘fieldthatshouldnotbechanged2’)
@attributes.delete(‘fieldthatshouldnotbechanged3’)
super(attributes)
end

I’m wondering though if there isn’t a better way to accomplish this and
I also got a gut-feeling the above will somehow screw up something else
but I can’t put a finger on it (and am probably overlooking the
obvious).

Any bright ideas/suggestions ?

Thanks in advance!

Piet.

On 6/21/06, Piet H. [email protected] wrote:

I found a workaround by overriding update_attributes in my model as follows:
I’m wondering though if there isn’t a better way to accomplish this and I
also got a gut-feeling the above will somehow screw up something else but I
can’t put a finger on it (and am probably overlooking the obvious).

Any bright ideas/suggestions ?

attr_protected: