开发者

CakePHP: How to specify models while retrieving data?

I want to retrive dat开发者_如何学JAVAa with recursive level 3. The problem is that It adds all 8 linked models but I need data from only three data models. Is there any way to ignore some models or specifically asked some models but not all. something like useModel('Model1', 'Model2')?


It's better to use the Containable behavior, which will allow you to specify find conditions like this:

$this->Post->find('all', array(
    'contain' => array(
        'Tag', 
        'Comment' => array(
            'User')
            )
        )
    );

Also, in conjunction with this, it's good to set $recursive to -1 in your AppModel.

class AppModel extends Model {
    var $recursive = -1;
    var $actsAs = array('Containable');
}

This will give you the finer control you need and ensure that your queries don't bloat as more relationships get added to your models over time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜