AliHichem/AliDatatableBundle — Issue #1: Joined tables with same field names
Author: chyshyya
Created: 2012-02-28 21:36:06+00:00
State: open

return $this->get('datatable')
->setEntity("AtlantCityBundle:City", "c")
->setFields(
array(
"Name" => 'c.name',
'Region' => 'r.name as rname',
'MyOwnActions' => 'c.id as cid',
"_identifier_" => 'c.id')
)
->addJoin('c.region', 'r', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN)
............................................
When joining two tables with the same field names we need to use ' as '. Without it the query will return only one field instead of two different. But... when we use ' as ', we will get an error on Sorting from a table. That's why I ask you to make little change in file .../Util/Datatable.php

protected function _getData($hydration_mode)
{
$request = $this->request;
$dql_fields = array_values($this->fields);
//$this->order_field = $dql_fields[$request->get('iSortCol_0')];
$fieldNameArray = \explode(' as ', $dql_fields[$request->get('iSortCol_0')]);
$this->order_field = $fieldNameArray[0];
...................................................
This code will explode field and if it contains or not ' as ' will return usable part of it. I check this change and it works nice.

Big thank you for your bundle.