Getting old values


#1

Hi all,

I’ve add :before_update event to my model
Before updating a record I want to check if new attributes differ to old
attr.

My question is how to retrieve old attributes in :before_update event ?

thanks


gratis egold 1$ http://shegold.com/


#2

Hello,

On Fri, Feb 17, 2006 at 03:53:06PM +0700, Superbiji wrote:

My question is how to retrieve old attributes in :before_update event ?

I asked the same question some days ago. The answer was use the
database.
The database is made to be queried and queries are cached. So just do a
MyModel.find(foo.id).bar

Hope this helps!

Regards,


Damien MERENNE removed_email_address@domain.invalid
http://www.cosinux.org/blogs/dam/

Chuck Norris doesn’t churn butter.
He roundhouse kicks the cows and the butter comes straight out.


#3

On 2/17/06, Damien MERENNE removed_email_address@domain.invalid wrote:

Hello,

I asked the same question some days ago. The answer was use the database.
The database is made to be queried and queries are cached. So just do a
MyModel.find(foo.id).bar

Thanks for your answer, I’ll try that

I do different way,
by overiding all attributes with
def ATTRIBUTE=(value)
@oldies[:attribute] = value
self[:attribute] = value
end

but I hope “getting old values” should be ActiveRecord’s standard
feature


jual beli gratis egold 1$ http://shegold.com/


#4

What exactly are you checking for?

ActiveRecord already has built in validation for uniqueness, take a
look at validates_uniqueness_of (pg 274 of AWD)

class User < ActiveRecord::Base
validates_uniqueness_of :name,
:on => :save,
:message => “is already being used”

And you can always call validate whenever you want, not just upon save.

On 2/20/06, Superbiji removed_email_address@domain.invalid wrote:

by overiding all attributes with


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

  • Nic

#5

On 2/21/06, Nic W. removed_email_address@domain.invalid wrote:

What exactly are you checking for?

I want to make sure ONE field is really modified before update.
for example, a record can’t be modified if field status is not changed


Jual Beli Gratis egold 1$ http://shegold.com/


#6

Superbiji wrote:

On 2/21/06, Nic W. removed_email_address@domain.invalid wrote:

What exactly are you checking for?

I want to make sure ONE field is really modified before update.
for example, a record can’t be modified if field status is not changed
Not to dispute your need for this, but what’s the use case here? Why
does it matter if an unchanged record is saved?