AliHichem / AliDatatableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities
MIT License
112 stars 72 forks source link

Select the Properties of an Entity that are Foreign Keys of that table. #112

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hi, i'm having this problem. When i want to select a field from an entity, and that field is a Foreign Key in that table, i get this error:

ContextErrorException: Notice: Undefined index: priority in C:\wamp2\www\crmba_prod\vendor\ali\datatable\Ali\DatatableBundle\Util\Factory\Query\DoctrineBuilder.php line 236

And the table shows 0 results.

The query:

return $this->get('datatable') //->setEntityManager($em) // Optional ->setEntity("BackendadminBundle:Activity", "a") // Replace "XXXMyBundle:Entity" by your entity ->setFields( array( "Created At" => 'a.createdAt', "Updated At" => 'a.updatedAt', "Start Activity"=> 'a.startActivity', "End Activity" => 'a.endActivity', "Description" => 'a.activityDescription', "Start Event" => 'a.startEvent', "End Event" => 'a.endEvent', "Note" => 'a.note', "Successful" => 'a.issuccessful', "Priority" => 'a.priority', ///// The FOREIGN KEY ///// "identifier" => 'a.id') // you have to put the identifier field without label. Do not replace the "identifier" ) //->addJoin('a.Actionresult', 'ar', \Doctrine\ORM\Query\Expr\Join::INNER_JOIN) //->setOrder("x.created", "desc") // it's also possible to set the default order ->setHasAction(true) ->setSearch(TRUE);

Pleas, help me. Thank you in advance.

AliHichem commented 9 years ago

You get this error because you are trying to get the field "priority" from the wrong entity, you should set priority like this

"Priority" => 'ar.priority', ///// The FOREIGN KEY /////

instead of what you did

"Priority" => 'a.priority', ///// The FOREIGN KEY /////