1

別の選択オブジェクトと結合するにはどうすればよいですか? このようなクエリを作成する必要があります

$select->join(array('alias' => $subSelect), 'on clause', 'array('*'), 'left');

ZF1.x ではこのようなことが可能でした。

ZF2 では、join メソッドの最初の引数はエイリアスを持つテーブルまたは配列の名前ですが、そこに \Select を配置できません。ここに置いても

$select->getSqlString($this->adapter->platform);

string は引用符で囲まれており、クエリは無効です。Join もブラケットを追加しません。本当に紛らわしいです。

4

2 に答える 2

1

多分これはあなたを助けるでしょう。これは、TableGateway にある実際の例です。

public function Profile($params)
{
    $result = $this->select(function (Select $select) use ($params) {
        $select
            ->columns(array(
                'ipaddress_type',
                'ipaddress',
                'domain'
            ))
            ->join('product_hosting_profile', 'product_hosting_profile.productid = webaccount.productid', array(
                'servers',
                'services'
            ))
            ->where(array(
                $this->adapter->getPlatform()->quoteIdentifierChain(array('webaccount', 'accountid')) . ' = ' . $this->adapter->getPlatform()->quoteValue($params['accountid']),
                $this->adapter->getPlatform()->quoteIdentifierChain(array('webaccount', 'productid')) . ' = ' . $this->adapter->getPlatform()->quoteValue($params['productid']),
                $this->adapter->getPlatform()->quoteIdentifierChain(array('webaccount', 'webaccountid')). ' = ' . $this->adapter->getPlatform()->quoteValue($params['webaccountid'])
            ))
            ->limit(1);
    });

    return $result->current();
}
于 2013-01-25T00:21:29.353 に答える
0
$subSelect=new Select(array('A'=>new TableIdentifier('target','CAT')));
    $subSelect->columns(array('fk_w','TI'=>'id','mtarget_f'=>new Expression('sum(F)'),
                'mcost'=>new Expression('round(sum(F*D.mcost),2)')))
    ->join(array('B'=>new TableIdentifier('item','CAT')),'B.id=A.fk_w',
            array())
                    ->join(array('D'=>new TableIdentifier('rate','CAT')),'A.dat=D.year and D.fk_c=B.CCODE and D.fk_b=A.fk_b',
                            array())
                            ->where->equalTo('Year', $year);



    $select=new Select(array('A'=>new TableIdentifier('item','CAT')));
    $select->columns(array('WID'=>'id','AID'=>'AID',
                'item'=>'ITEM_ID','Wtitle'=>'WTITLE'))
    ->join(array('B'=>new TableIdentifier('cn','CAT')),'B.id=A.CCODE',
            array('Ct'=>'name'))
    ->join(array('S'=>$subSelect),'S.fk_w=A.id',array('Mtarget'=>'mcost',
                    'MTarget'=>'m_target',                  
                    'TID'),'left');
于 2016-10-11T08:28:15.663 に答える