我有用户HABTM专业。在用户编辑中,有一个专业的复选框列表。当我在用户模型中定义HABTM关系时,它正在工作。但由于该关系中断了其他功能,我将其移除并将其放入用户控制器中
$this->User->bindModel(
array(
'hasAndBelongsToMany' =>
array(
'Profession' =>
array(
'className' => 'Profession',
'joinTable' => 'professions_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'profession_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
)
)
);
绑定函数的返回值也为true。
现在,当我调用$this->User->saveAll($this->data)时,不再在professions_users表中创建行。
有什么想法吗?
发布于 2010-11-24 14:24:13
bindModel
的默认行为是为一个find
操作而存在,然后恢复为默认关联。您可能认为save
操作不会触发此操作,但是如果您使用Cake's count-caching feature,或者使用带有执行find
的afterSave
回调的行为,您可能就错了。
尝试将false
作为Model::bindModel
调用的第二个参数传递。这将使您的动态绑定持续到请求的持续时间。通过调用Model::resetAssociations
,您始终可以在saveAll
完成后显式地重置关联。
https://stackoverflow.com/questions/4266352
复制相似问题