【问题标题】:Can not get second table value in inner join in CakePHP无法在 CakePHP 的内部连接中获取第二个表值
【发布时间】:2016-05-11 08:07:27
【问题描述】:

我在 CakePHP 框架中工作。我想加入两张桌子。所以我写了如下查询。

$details=$this->Deal->find('all',array('joins'=>array(
                          array(
                           'table'=>'merchants',
                           'alias'=>'Merchant',
                           'fields' => array('Merchant.username'),
                           'conditions' =>array('Merchant.id=Deal.merchant_id')
                          )
                        ),'conditions'=>array('Deal.id'=>$id)));
    echo "<pre>";
    print_r($details);

当我打印详细信息时,它只会给出 deal 表记录。这里我也想要Merchant.username

那么我必须在上述查询中进行哪些更改?

注意:-我正在使用 CakePHP 1.3.13 版

【问题讨论】:

    标签: php mysql cakephp cakephp-1.3


    【解决方案1】:
    $details = $this->Deal->find('all', array('joins' => array(
            array(
                'table' => 'merchants',
                'alias' => 'Merchant',
                'conditions' => array('Merchant.id=Deal.merchant_id')
            )
        ), 'conditions' => array('Deal.id' => $id),
        'fields' => array('Merchant.username', 'Deal.*'),
            )
    );
        echo "<pre>";
        print_r($details);
    

    【讨论】:

    • 很好用。所以我必须在字段中写 Deal.*
    • 如果你想要完整的值。
    • 请不要只回答代码,至少用一句话解释您的代码如何解决问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    • 2014-11-17
    相关资源
    最近更新 更多