Google Groups Home
Help | Sign in
I don't see a way to alias Rails' auto-timestamp columns...
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
ed_ruder  
View profile
 More options Sep 12 2007, 3:13 pm
From: ed_ruder <ed.ru...@gmail.com>
Date: Wed, 12 Sep 2007 12:13:42 -0700
Local: Wed, Sep 12 2007 3:13 pm
Subject: I don't see a way to alias Rails' auto-timestamp columns...
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ed_ruder  
View profile
 More options Sep 13 2007, 2:39 am
From: ed_ruder <ed.ru...@gmail.com>
Date: Wed, 12 Sep 2007 23:39:45 -0700
Local: Thurs, Sep 13 2007 2:39 am
Subject: Re: I don't see a way to alias Rails' auto-timestamp columns...
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:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ed_ruder  
View profile
 More options Sep 13 2007, 4:51 pm
From: ed_ruder <ed.ru...@gmail.com>
Date: Thu, 13 Sep 2007 13:51:30 -0700
Local: Thurs, Sep 13 2007 4:51 pm
Subject: Re: I don't see a way to alias Rails' auto-timestamp columns...
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:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google