Is it possible that $row->getEntity() returns null
lmeyer opened this issue · 2 comments
lmeyer commented
Hello,
Sentry reported an error that seems weird.
Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function getBottle() on null in xxxx/AppBundle/Grid/TransactionGrid.php:200
Involved code is
$column = new TextColumn([
'id' => 'format',
'field' => 'bottle.format.name',
'title' => 'Format',
'source' => true,
'sortable' => true,
'operatorsVisible' => false,
]);
$column->manipulateRenderCell(function($value, $row) {
return $row->getEntity()->getBottle()->getFormat()->getName();
});
$this->grid->addColumn($column, 14);
So getEntity returned null this time.
The website is heavily used, but the problem appeared only one time so it's not a big deal. But I prefer to ask.
Regards,
petrofcikmatus commented
Hi @lmeyer,
yes, according to code in APY\DataGridBundle\Grid\Row
, method Row::getEntity()
can return null
or object
.
<?php
namespace APY\DataGridBundle\Grid;
use Doctrine\ORM\EntityRepository;
class Row
{
//...
/**
* @return null|object
*/
public function getEntity()
{
$primaryKeyValue = current($this->getPrimaryKeyValue());
return $this->repository->find($primaryKeyValue);
}
//...
}
npotier commented
Hello, I'm closing this issue since the behaviour is normal and not a bug