1

I have a "User" model in cakePHP associated with multiple other models.

    public $belongsTo = array(
        'Reference' => array(
            'className' => 'Reference',
            'foreignKey' => 'reference_id',
        ),
        'SecurityQuestion' => array(
            'className' => 'SecurityQuestion',
            'foreignKey' => 'question_id',
        )
    );

    public $hasMany = array(
        'UserReview' => array(
            'className' => 'UserReview',
            'foreignKey' => 'user_id',
            'dependent' => true,
        ),
        'UserLicense' => array(
            'className' => 'UserLicense',
            'foreignKey' => 'user_id',
            'dependent' => true,
        ),
        'UserCertification' => array(
            'className' => 'UserCertification',
            'foreignKey' => 'user_id',
            'dependent' => true,
        ),
        'UserFavorite' => array(
            'className' => 'UserFavorite',
            'foreignKey' => 'user_id',
            'dependent' => true,
        ),
   }

the code below return all the Models.

$this->User->find('first', array('conditions' => array('User.id' => 15)));

But

$this->User->find('first', array('contain' => 'UserProfile','conditions' => array('User.id' => 15)));

I guess to return User and UserProfile, but it again return All associations.

Please Help.

4

2 に答える 2

2

'Containable' をオンザフライでロードすることもできます

$this->User->Behaviors->load('Containable');
$this->User->find('first', array('contain' => 'UserProfile','conditions' => array('User.id' => 15)));
于 2014-04-09T05:47:51.977 に答える