cakephp: find statement with 'contain'

2019-07-18 07:44发布

the following User model function is from MilesJones forum plugin. Can someone tell me on what is the use of 'contain' in the find stmt. I couldn't find any example with contain in the cakephp cookbook. Any helps is appreciated.

public function getProfile($id) {
    return $this->find('first', array(
        'conditions' => array('User.id' => $id),    
        'contain' => array(
            'Access' => array('AccessLevel'),
            'Moderator' => array('ForumCategory')
        )
    ));
}

标签: cakephp find
2条回答
我命由我不由天
2楼-- · 2019-07-18 08:00

Here is cakephp documentation about contain

查看更多
Viruses.
3楼-- · 2019-07-18 08:17

By default when a find statement executes cake pulls all the data from the model on which the find function is executing plus all the data from the models that are associated with the model. Most of the time you don't need that extra data, Cake has containable behaviour for exactly that purpose. You can specify which associated model's data you want in your result.

In the above example find statement will fetch the first record from the User model plus associated data from Access and Moderator models.

Here is the link from cakephp book http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html

查看更多
登录 后发表回答