简体   繁体   中英

columns of joined table missing

I'm missing the columns of a joined table. I have two tables like:

t_q_filialen 1 --> n t_mandant

I did my select statement in my model as follows:

    $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']);   

I expected to get the column name with the given alias 'filiale' like this in my view script:

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

I get an error.

Unknown column 't_mandant.filiale' in 'field list'

If I change back to 'geschid' which is the foreign key-column in the table t_mandant and try:

var_dump(get_object_vars($mandant));

the columns from the table 't_q_filialen' are not in the collection.

What's wrong?

I have a small idea that I could be something with paginator. I instantiate paginator like this:

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

How can I change this, so that my join will be accepted? Might have something to do with this:

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

In other models without pagination I use this one and it works:

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

So which could be the solution? I really would prefer the last possibility, but I have no idea how to use it in combination with paginator. Any help appreciated!

I listed several ideas, but my goal would be, to have the columns of both tables in my collection with the paginator-object.

oh my god, I just tried:

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

Without the resultsetprototype

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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