CakePHP如何从不同的表中获取照片?

CakePHP如何从不同的表中获取照片?,cakephp,Cakephp,您好,我有两个table friends和Gallery,我想在Friend.Friend_id=1和Gallery.user_id=1的两个表之间使用CakePHP模型关联 朋友 画廊 上面两张表我想加入。但是我不能参加。请帮帮我。经过大量研究,我终于得到了答案。此代码有助于其他- //$user_id=$this->Session->read('Auth.User.id'); $user_id=1; $this->Friend->bindModel(

您好,我有两个table friends和Gallery,我想在Friend.Friend_id=1和Gallery.user_id=1的两个表之间使用CakePHP模型关联

朋友

画廊


上面两张表我想加入。但是我不能参加。请帮帮我。

经过大量研究,我终于得到了答案。此代码有助于其他-

   //$user_id=$this->Session->read('Auth.User.id');
   $user_id=1;
   $this->Friend->bindModel(
                array('hasOne' => array(
                        'Gallery' => array(
                            'className' => 'Gallery',
                            'foreignKey' => FALSE,
                            'conditions' => array('Friend.friend_id=Gallery.user_id'),                                
                            'type' => 'LEFT'
                        )
                    )
                )
       );

    $this->Friend->bindModel(array('belongsTo' => array('User' => array('className' => 'User', 'foreignKey' => 'friend_id', 'conditions'=>array('Friend.user_id'=>$user_id)))));

   $data = $this->Friend->find('all');
   pr($data);

你只需要SQL查询吗?不,我想在CakePHPread中建立关联模型,以获取基本信息,
id   user_id    photo
------------------------
1      1      photo1.jpg
2      6      photo2.jpg
3      5      photo3.jpg
   //$user_id=$this->Session->read('Auth.User.id');
   $user_id=1;
   $this->Friend->bindModel(
                array('hasOne' => array(
                        'Gallery' => array(
                            'className' => 'Gallery',
                            'foreignKey' => FALSE,
                            'conditions' => array('Friend.friend_id=Gallery.user_id'),                                
                            'type' => 'LEFT'
                        )
                    )
                )
       );

    $this->Friend->bindModel(array('belongsTo' => array('User' => array('className' => 'User', 'foreignKey' => 'friend_id', 'conditions'=>array('Friend.user_id'=>$user_id)))));

   $data = $this->Friend->find('all');
   pr($data);