我正在 CakePHP 中创建一个问答应用程序,我想在某些情况下排除我的关联。想象一下:
我使用 $this->Question->findAll(); 在第一页列出所有问题。因为我的模型中有以下关联:
public $hasMany = array('Answer' =>
array('className' => 'Answer',
'order' => 'Answer.created DESC',
'foreignKey' => 'post_id',
'dependent' => true,
'exclusive' => false,
)
);
所有答案都将在开始页面上被选中,这不是最佳选择。我该怎么做才能排除这种特定方法中的答案?
谢谢
最佳答案
我快速查看 CakePHP API显示你有一个 unbindModel模型上的方法。 所以在你的例子中你可以这样做:
$this->Question->unBindModel(array('hasMany' => array(’Answer’)))
或者,您可以使用 Containable仅从 MySQL 选择当前页面 View 所需的片段的行为。
关于php - 我如何从 CakePHP 中的关联模型中排除记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/377920/