Mike Reeves Tue Jan 18 18:38:01 -0500 2011

Subject: Virtual Attributes

So, here's an example I came across right off the bat.

I have a user model, this model has the following attributes:

id, username, email, crypted_password, password_salt, created_at, updated_at

My form for the model has the following columns:

username, email, password, confirm_password

Obviously, I don't want things like confirm_password to be a column in my database, but I would like to access it inside the model for validation purposes. Password is different from crypted_password because the latter is, well, encrypted. So, I need 2 virtual attributes. password, and confirm_password.

I've setup set/get_password(), and set/get_confirm_password. Setting and accessing $user->password and $user->confirm_password is working fine, but when I call $user->save(), I get an error stating that password is not in the field list.

Any help is appreciated, I've got a new project starting this week, and I'd love to use this ORM in the project.


Kien La Fri Jan 21 23:16:46 -0500 2011

Could you the relevant code snippet and stack trace?

Taylor Otwell Mon Jan 31 12:28:11 -0500 2011

Wouldn't just explicitly declaring the property "confirm_password" on the model prevent PHP ActiveRecord from knowing about it and accomplish what you want?

I think this would prevent the ActiveRecord\Model's magic "__set" method from firing and thus the ORM wouldn't know about the property.

(1-2/2)