There is a User table, and a UserDetail table related to User table. Here is my code of UserModel in PHP :
<?php
class UserModel
{
public function initialize()
{
$this->hasOne(
'detailId', 'UserDetailInfo', 'id', array(
'alias' => 'detailInfo',
'foreignKey' => array(
'action' => Relation::ACTION_CASCADE
)
)
);
}
}
Here is my question, everytime i get UserDetail from UserModel use $user->detailInfo property, is it a brand new Object? The code following not work:
<?php
//this code does not work!
$user->detailInfo->setName('xxx');
$user->detailInfo->setAge(23);
$user->save();
//this code works!
$user->detailInfo->setName('xxx')->setAge(23);
$user->save();
why?