unbindModel是如何在蛋糕中发生的?
$this->User->unbindModel(array('hasAndBelongsToMany' => array('Friend')));
我在函数的开头写了这个.但它仍在查询“朋友”模型.在函数中间调用了paginate().所以我认为分页器可能正在生成查询.
我在paginate之前添加了一个unbindModel调用,它现在可以工作了.
$this->User->unbindModel(array('hasAndBelongsToMany' => array('Friend'))); $user = $this->paginate("User",array("User.first_name LIKE" => $user["User"]["first_name"]));
From the manual:
原文链接:https://www.f2er.com/php/137983.htmlRemoving 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()或对模型执行任何其他操作之后,取消绑定将被反转.