Select 加入 table 和 Zend\Db\Sql 时 return 的列

Select Columns to return when joining a table with Zend\Db\Sql

我只想 return 一栏 (per.cd_acao),所以我尝试了类似的方法:

$select->from(array('act' => 'tb_acao'))
           ->join(array('per' => 'tb_perfil_acao'),
                'per.cd_acao = act.cd_acao',
                array('cd_acao'),
                $select::JOIN_INNER
            );

但这会生成如下查询字符串: SELECT "act".*, "per"."cd_acao" AS "cd_acao" FROM "tb_acao" AS "act" INNER JOIN "tb_perfil_acao" AS "per" ON "per"."cd_acao" = "act"."cd_acao" WHERE "per"."sq_perfil" = '89'

当我想要 none 时,它会带来第一个 table 的所有列。我在这里错过了什么?

更新

总结:当我不在select对象中通知'columns'时,它默认为return所有列给我。但是当我加入时,我不希望任何列被第一个table编辑return。

一个空数组就足够了

$select->from(array('act' => 'tb_acao'))
           ->columns(array())
           ->join(array('per' => 'tb_perfil_acao'),
                'per.cd_acao = act.cd_acao',
                array('cd_acao'),
                $select::JOIN_INNER
            );

试试这个查询

use Zend\Db\Sql\Sql;

protected $tableGateway;
public $adapter;

public function __construct(TableGateway $tableGateway)
{
    $this->tableGateway = $tableGateway;
}

publice function getData(){
    $adapter = $this->tableGateway->getAdapter();
    $sql = new Sql($adapter);
    $select = $sql->select();
    $select->from('tb_acao')
       ->join('per'),
            'per.cd_acao = act.cd_acao',
            array('cd_acao'),
        );
    $statement = $sql->prepareStatementForSqlObject($select);
    $results = $statement->execute();

    return $results;
}