【问题标题】:columns of joined table missing连接表的列丢失
【发布时间】:2025-12-16 11:10:01
【问题描述】:

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

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”

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

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-framework zend-db zend-framework3 zend-db-select


    【解决方案1】:

    天哪,我刚试过:

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

    没有结果集原型

    【讨论】:

    • 可能在你的'new Mandant()'对象中你没有那些字段?