This project is archived and is in readonly mode.

#6505 new
qoobaa

attr_writeonce in AR models

Reported by qoobaa | March 2nd, 2011 @ 12:45 PM

I've spent a while looking for "write once" functionality in Active Record, but it seems there's anything like that at the moment. I'd expect that attr_writeonce allows to change the attribute from nil to a value (exactly once). It's similar to attr_readonly but it works for persisted records. Do you think it's useful? I can try to prepare a patch if there's a chance that it gets merged to Rails.

Method attr_readonly seems to be kind of "badly named". It actually allows to write a "readonly" attribute, but only when creating the record. I think it'd better to use something like

attr_writeonce :title, :on => :create

IMO attr_readonly shouldn't allow to change the attribute at all.

No comments found

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages