5

我正在 CakePHP 中创建一个问答应用程序,并且在某些情况下我想排除我的关联。想象一下:

我使用 $this->Question->findAll(); 在第一页列出所有问题。由于我的模型中有以下关联:

public $hasMany = array('Answer' =>
        array('className' => 'Answer',
            'order' => 'Answer.created DESC',
            'foreignKey' => 'post_id',
            'dependent' => true,
            'exclusive' => false,
        )
    );

所有答案都将在开始页面被选中,这不是最佳的。我该怎么做才能排除这种特定方法中的答案?

谢谢

4

2 回答 2

5

我快速浏览一下CakePHP API,发现您在模型上有一个unbindModel方法。所以在你的例子中你可以这样做:

$this->Question->unBindModel(array('hasMany' => array(’Answer’)))

或者,您可以使用Containable行为仅从 MySQL 中选择当前页面视图所需的部分。

于 2008-12-18T14:20:58.293 回答
0

如果您使用的是 CakePHP 1.2,您应该考虑 Containable Behaviour。有关详细信息,请参阅http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/

于 2008-12-18T14:39:35.667 回答