Unfortunately, while elegant, alias_attribute() doesn't work as I
expected. It does define getter, setter, and query methods for the
alias, but that's not sufficient.
ActiveRecord::Timestamp.create_with_timestamps and
update_with_timestamps use write_attribute(), which sets values in the
@attributes hash, and doesn't use the setter that alias_attribute set
up.
So, back to square one.
Ed
P.S. The work-around that does work for this is to define a
before_save method in the model that updates the legacy column. I was
hoping for a something that would hook Rails' existing automatic
timestamping functionality. :-[
On Sep 12, 11:39 pm, ed_ruder <ed.ru...@gmail.com> wrote:
> I think I found the solution to my problem here:
http://rails.raaum.org/activerecord.html#alias.
> If my legacy DB has a datetime-equivalent column named
> "last_modified", I ought to be able to do this in my model:
> alias_attribute :updated_at, :last_modified
> Ed
> On Sep 12, 12:13 pm, ed_ruder <ed.ru...@gmail.com> wrote:
> > I'm working with a legacy database that has columns for creation and
> > updated times, but they aren't called "created_[at|on]" and
> > "updated_[at|on]". I haven't found a "proper" way to tell Rails to use
> > other columns for its automagic timestamping functionality. Am I out
> > of luck?
> > Thanks for any help/advice!
> > Ed