class UserEducation extends EMongoEmbeddedDocument {
public $institution_name;
public $level_of_study;
.
.
public static function model($className=__CLASS__) {
return parent::model($className);
}
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('institution_name, level_of_study, field_of_study', 'required'),
array('institution_name', 'length', 'max' => 200),
.
.
);
}
.
.
$user->education[$i] = new UserEducation;
$user->education[$i]->institution_name = $education['institution_name'];
.
.
if($user->validate()) { //This thing is all bypassed and data is always saved without any validation and I can't do $user->education->validate() since that is undefined method.
$user->save();
}
.
.
.
.
public $education;
.
.
public function behaviors() {
return array(
.
.
array(
'class' => 'ext.YiiMongoDbSuite.extra.EEmbeddedArraysBehavior',
'arrayPropertyName' => 'education', // name of property, that will be used as an array
'arrayDocClassName' => 'UserEducation' // class name of embedded documents in array
),
.
.
);
}
--
Nagy Attila Gabor