AdminModel hasOne profile
$this->hasOne('profileId', 'Cntysoft\Framework\UserCenter\Admin\Model\Profile', 'id',array(
'alias' => 'profile',
'foreignKey' => array(
'action' => Relation::ACTION_CASCADE
)
));
profile
public function initialize()
{
$this->belongsTo('id', 'Cntysoft\Framework\UserCenter\Admin\Model\Admin', 'profileId', array('alias' => 'admin','foreignKey' => array(
'action' => Relation::ACTION_CASCADE
))
);
}
i try like this
$profile->assignBySetter(array(
'recentApps' => array(),
'wallPaper' => Constant::P_DEFAULT_WALLPAPER,
'vdesktopNum' => Constant::P_DEFAULT_VD_NUM,
'appVdMap' => array(),
'appVdOrder' => array()
), true);
$adminModel->profile = $profile;
$adminModel->create();
Profile and admin data both are saved to database; but admin's profileId column is null , expect the new inserted profileid
My way I like this, it works , but is not beauty, Anyone has a better way? many thank
$db = Kernel\get_db_adapter();
try {
$db->begin();
$profile->create();
$adminModel->setProfileId($profile->getId());
$adminModel->assign($data);
$adminModel->create();
$db->commit();
} catch (Exception $ex) {
$db->rollback();
throw $e;
}