首页 > 解决方案 > 连接表的列丢失

问题描述

我缺少连接表的列。我有两张桌子,例如:

t_q_filialen 1 --> n t_mandant

我在我的模型中做了如下选择语句:

    $select= new Select ();         //another try ('t_mandant','t_q_filialen');
    $select->columns(['id', 'cccid' ,'geschid', 'name', 'langname','filiale']);
    $select->from('t_mandant');
    $select->join('t_q_filialen', 't_q_filialen.id=t_mandant.geschid ', [ 'filialeid'=>'id','filiale'=>'name']);   

我希望在我的视图脚本中获得具有给定别名 'filiale' 的列名,如下所示:

$this->escapeHtml($mandant->filiale);

我得到一个错误。

“字段列表”中的未知列“t_mandant.filiale”

如果我改回 'geschid' 这是表 t_mandant 中的外键列并尝试:

var_dump(get_object_vars($mandant));

表“t_q_filialen”中的列不在集合中。

怎么了?

我有一个小想法,我可以成为分页器。我像这样实例化分页器:

$resultSetprototype=new ResultSet();
$resultSetprototype->setArrayObjectPrototype(new Mandant());
$paginatorAdapter= new DbSelect($select, $this->tableGateway->getAdapter(), $resultSetprototype);
$paginator=new Paginator($paginatorAdapter);
return $paginator;

我怎样才能改变这一点,以便我的加入将被接受?可能与此有关:

$resultSetprototype->setArrayObjectPrototype(new Mandant());

在其他没有分页的模型中,我使用这个模型,它可以工作:

$rowset = $this->tableGateway->adapter->query($statment, "execute");

那么这可能是解决方案吗?我真的更喜欢最后一种可能性,但我不知道如何将它与分页器结合使用。任何帮助表示赞赏!

我列出了几个想法,但我的目标是让我的集合中的两个表的列都带有分页器对象。

标签: zend-frameworkzend-dbzend-framework3zend-db-select

解决方案


天哪,我刚试过:

$paginatorAdapter= new DbSelect($select, $this->tableGateway->getAdapter());

没有结果集原型


推荐阅读