Getting old values

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/

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 [email protected]
http://www.cosinux.org/blogs/dam/

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

On 2/17/06, Damien MERENNE [email protected] 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/

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 [email protected] wrote:

by overiding all attributes with


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

  • Nic

On 2/21/06, Nic W. [email protected] 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/

Superbiji wrote:

On 2/21/06, Nic W. [email protected] 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?