【发布时间】:2010-09-16 00:07:48
【问题描述】:
我在帐户和用户表之间存在一对一的关系,我正在尝试在帐户模型的 beforeSave 中进行所有预处理,但似乎我只能更改$this->data['Account'][...] 的值而不是 $this->data['User'][...],为什么会这样?
function beforeSave() {
// Check if this is a create or update action
if (empty($this->data['Account']['uid'])) {
$this->data['Account']['uid'] = uniqid();
$this->data['Account']['date_registration'] = date('Y-m-d');
$this->data['Account']['state'] = 1;
// this won't work
$this->data['User']['password'] = Security::hash($this->data['User']['password'], null, true);
}
return true;
}
另一个问题是在 beforeSave 事件中检查用户是否正在更新或创建模型的最佳方法是什么,检查 empty($this->data['Account']['id'])) 吗?
谢谢。
【问题讨论】:
标签: cakephp model callback associations