Could this be a bug in Sonata Admin bundle?
Let's say I have an entity A that can have multiple B's. To see this in my database, I would write something like
select * from a inner join b on b.a_id = a.id;
This would give me a result set with every A and the corresponding B (if any), for example:
| a.id | b.id | b.a_id |
| 1 | 1 | 1 |
| 2 | 2 | 2 |
| 2 | 3 | 2 |
In my admin class, I've overridden the createQuery
function like this:
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$rootAlias = current($query->getRootAliases());
$query
->innerJoin('b', 'b', 'WITH', $rootAlias.'.b = b')
->addSelect('b');
return $query;
}
The above gives me the desired SQL and the SQL itself returns the data as shown above, but Sonata Admin list view displays it like this:
| a.id | b.id | b.a_id |
| 1 | | |
| | 1 | 1 |
| 2 | | |
| | 2 | 2 |
| | 3 | 2 |
So it seems I'm getting an extra row for each A-entity with no B-associations, followed by the B-entities with none of the values from the A-entity.
Why does that happen? Is it a bug? And how can I work around it?