Multiple Joins in Grid
I can use join in a grid, but for a single field.
I have the next problem..
I have a table that has two id fields referencig the same field on other table.开发者_如何学JAVA
Example:
table1 id,name
table2: iduser1,iduser2 (both are fk to id on table1).
I have this values on table 1
id: 1 -> name: user1
id: 2 -> name: user2
and on table2 I have a pair of values 1,2
iduser1: 1
iduser2: 2
If I make a join like this
$g->dq->join('table1','table1.id=table2.iduser1')->field('table1.name iduser1')->field('table1.name iduser2')
$g->addColumn('text','iduser1');
$g->addColumn('text','iduser2');
The result is name of user1 twice on the grid, but not user1,user2
I have tested to add another join() but without success. Can I have some help or maybe some direction about what I'm doing wrong ?
Thanks a lot
You can perform two joins.
// primary table
$grid->setSource('table1');
// Joins all tables
$grid->dq->join('table2','table2.iduser1=table1')
->join('table1 user2');
// This is how you add fields from linked table
$grid->dq->field('user2.name name2');
$grid->addColumn('text,'name2','Linked User');
精彩评论