Hello Augusto,
I specially don't like the Yii philosophy of using the same model
class in forms and in data persistence, because it leads to problems
like yours. You could use the scenarios, but either it sometimes does
not work well, or makes your ruleset quite complicated after a while.
So in my practice I usually have a separate model for the form
(extending CFormModel), and the model that I use for persistence.
So I would create one class like:
class Users extends EMongoDocument {
public $email;
public $name;
public $password;
public $lastLoginDate;
// etc
}
then have a registration form like:
class RegistrationForm extends CFromModel {
public $email;
public $name;
public $password;
public $password_repeat;
}
(and maybe a login form like):
class LoginForm extends CFormModel {
public $email;
public $password;
}
In this case each of them had one or just a few scenarios, easily
understandable ruleset, and you shouldn't worry about the changes
resulting in surprising results.
You can use the mass update to move values between models using the
getAttributes/setAttributes methods:
$dbUser->setAttributes($regForm->getAttributes());
// or to avoid warnings about unsafe attributes:
$dbUser->setAttributes(array_diff_key($regForm->getAttributes(),
array('password_repeat' => 1)));
--
Nagy Attila Gabor