How to exclude entries from a related model in CakePHP?

I am creating a Q&A application in CakePHP, and in some cases I want to exclude my associations. Imagine the following:

I list all the questions on the first page using $ this-> Question-> findAll () ;. Since my model has the following association:

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

All answers will be selected on the start page, which is not optimal. How can I do to exclude answers in this particular method?

thanks

+5
source share
2 answers

I will quickly look through the CakePHP API shows that you have unbindModel on the model. So in this example you can do this:

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

Containable, MySQL, .

+5
0

All Articles