July 29, 2014, 7:18pm
My class ‘Escritorio’, have a relation hasMany.
@property Empresa $empresas
Empresa has a column escritorio_id <---- foreign key for escritorio
In the class EscritorioSearch how do i include this relation into search() method?
And show it on GridView?
July 30, 2014, 8:25am
There’s some information here which might help.
If it works the same as Yii 1.1.x, you’ll need to group on the ID field of the primary table to prevent the row counts from being incorrect when joining a has many relation. I’d be interested to know if this is still the case.
July 30, 2014, 6:36pm
In my columns on gridView, setting the property like this:
'attribute' => 'empresas',
'value' => 'empresas.nome',
*empresas = companies
*empresas.nome = companies name / Attribute Name.
this is my HasMany relation…
office -> HasMany -> Companies
But in the gridView, the columns show the message: ‘Not Defined’.
[b]If i like to search in gridview this works!
Add this lines to modelSearch to work the search columns by companie name.
$query = Escritorio::find();
$subQuery = Empresa::find()
$query->leftJoin(['empresas' => $subQuery], 'empresas.escritorio_id = psw_escritorio.id');
I created a test enterprise and i searched for it.
1 - All Registers
2 - Registers Filtered
What is wrong to not show the company name in gridview?
I resolved the problem.
Created a function, this returned all companies separated by comma