douhu2890
2015-02-03 04:28
浏览 15
已采纳

内部联接在cakephp中不起作用

i have two tables in my database salaries model is Salary and userdetais model is Userdetail in which i want to fetch result bye comparing id and user_id code is

$this->Salary->find('all',
  array(
      'joins'=>array(
      'table'=>'erp_userdetails',
      'alias' => 'Userdetail',
      'type' => 'INNER',
      'conditions' => array('Salary.user_id' => 'userdetail.id')
       )
     )
  );
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douxiongzhen2126 2015-02-03 04:51
    已采纳

    Try this

    this->Salary->find('all',
                array('joins'=>
                        array(
                            array('table'=>'erp_userdetails',
                                  'alias' => 'Userdetail',
                                  'type' => 'INNER',
                                  'conditions' => array('Salary.user_id' => 'userdetail.id')
                            )
                        )
                    )
            );
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doujue1246 2015-02-03 04:54

    You can use cakephp relational model. Add belongsTo relation on Salary model

    public $belongsTo=array(
        "Userdetail"=>array(
            "foreignKey"=>"user_id"
        )
    )
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题