简体   繁体   English

Zend Framework 2 TableGateway返回空结果集

[英]Zend Framework 2 TableGateway returning empty resultset

I am just getting started with developing with Zend Framework 2 and I've run into a roadblock. 我刚刚开始使用Zend Framework 2进行开发,但是遇到了障碍。

At it's simplest expression, the fetchAll function works: 用最简单的表达式,fetchAll函数起作用:

public function fetchAll()
{
    $resultSet = $this->tableGateway->select();
    return $resultSet;
}

However, when I attempt to mix in the join in the following way: 但是,当我尝试通过以下方式混合联接时:

public function fetchAll()
{
    $sql = new Sql($this->tableGateway->getAdapter());

    $select = $sql->select();
    $select->from('Entreprise')
        ->columns(array('id', 'nom', 'categorie_id'))
        ->join(array('C' => 'Categorie'), 'categorie_id = C.id', array('categorie' => 'nom'), \Zend\Db\Sql\Select::JOIN_INNER);
    $resultSet = $this->tableGateway->selectWith($select);
    return $resultSet;
}

The resulting query is: 结果查询为:

SELECT "Entreprise"."id" AS "id", "Entreprise"."nom" AS "nom", "Entreprise"."categorie_id" AS "categorie_id", "C"."nom" AS "categorie" FROM "Entreprise" INNER JOIN "Categorie" AS "C" ON "categorie_id" = "C"."id"

The table names, columns are fine since the query doesn't throw an error, but instead simply returns an empty result set. 表名,列很好,因为查询不会引发错误,而是只返回一个空结果集。 Even removing the join and just leaving the following code doesn't help. 即使删除联接并仅留下以下代码也无济于事。

public function fetchAll()
{
    $sql = new Sql($this->tableGateway->getAdapter());

    $select = $sql->select();
    $select->from('Entreprise');
    $resultSet = $this->tableGateway->selectWith($select);
    return $resultSet;
}

Which makes me believe it's simply something wrong with how I get the adapter or instantiate the select, but I just can't seem to figure it out or find any solution. 这使我相信,获取适配器或实例化选择的方式完全是错误的,但是我似乎无法弄清楚它或找到任何解决方案。

Can anyone help me figure what I'm doing wrong? 谁能帮我弄清楚我在做什么错?

The following code works perfectly: 以下代码可以完美运行:

public function fetchAll()
{
    $sql = new Sql($this->tableGateway->getAdapter());

    $select = $sql->select();
    $select->from('Entreprise')
        ->columns(array('id', 'nom', 'categorie_id'))
        ->join(array('C' => 'Categorie'), 'categorie_id = C.id', array('categorie' => 'nom'), \Zend\Db\Sql\Select::JOIN_INNER);
    $resultSet = $this->tableGateway->selectWith($select);
    return $resultSet;
}

...it was a typo that had been entered by accident in another file... ...这是另一个文件中偶然输入的错字...

Thanks Sam for the lead, ridiculously simple, but I just didn't think of trying! 感谢Sam的带领,这很简单,但我只是没有想到尝试!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM