cake中unbindModel是怎么发生的?
$this->User->unbindModel(array('hasAndBelongsToMany' => array('Friend')));
我在一个函数的开头写了这个。但它仍然查询“ friend ”模型。在函数中间调用了 paginate() 。所以我认为分页器可能会生成查询。
我确实在分页之前添加了一个 unbindModel 调用,它现在可以工作了。
$this->User->unbindModel(array('hasAndBelongsToMany' => array('Friend')));
$user = $this->paginate("User", array("User.first_name LIKE" => $user["User"]["first_name"]));
unbindModel 是否取消绑定(bind)每个查询?还是在整个函数调用期间解除绑定(bind)?
最佳答案
Removing or adding associations using bind- and unbindModel() only works for the next model operation unless the second parameter has been set to
false
. If the second parameter has been set tofalse
, the bind remains in place for the remainder of the request.
换句话说,在您 paginate()
或 find()
或对模型执行任何其他操作后,解除绑定(bind)将被逆转。
关于php - CakePhp 中的 unbindModel 调用。它是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1587224/