manipulateRenderCell returns wrong entity via $row->getEntity()
Hey guys,
I have a small problem which seems to be working in 2013. https://github.com/APY/APYDataGridBundle/issues/391#issuecomment-16038709
$priceColumn = new BlankColumn(array('id' => 'price', 'title' => 'Price'));
$priceColumn->setSafe(false)->manipulateRenderCell(
function($value, $row, $router) {
/** @var string $value */
/** @var \APY\DataGridBundle\Grid\Row $row */
/** @var \AppBundle\Routing\Router $router */
/** @var Order $order */
$order = $row->getEntity();
return $row->getEntity()->getId();
}
);
$grid->addColumn($priceColumn);
This example above returns always the number 3. But expected is 1, 2, 3, 4, 5, 6, 7, ...
And this returns correct key.
$priceColumn = new BlankColumn(array('id' => 'price', 'title' => 'Price'));
$priceColumn->setSafe(false)->manipulateRenderCell(
function($value, $row, $router) {
/** @var string $value */
/** @var \APY\DataGridBundle\Grid\Row $row */
/** @var \AppBundle\Routing\Router $router */
/** @var Order $order */
$order = $row->getEntity();
return implode(', ', $row->getPrimaryKeyValue());
}
);
$grid->addColumn($priceColumn);
This returns correct id of entity.
But is this intention or a bug? Because $row->getEntity() is the entity for the row in my understanding 👍
Maybe someone can fix this 👍 Thanks.
Thanks for reporting. We should investigate this /cc @hmert
Ah maybe the issue is because my entity has this annotation.
* @GRID\Source(columns="orderIdentifier, state, pickupDate", filterable=false)
I found out that:
$row->getPrimaryFieldValue();
Returns always the orderIdentifier - but each time this is different. So thats working.
return implode('', $row->getPrimaryKeyValue());
Returns the order identifier, too.
But I have an ID field. But this is hidden for the customer ;-)
I tried to work around this via:
$order = $orderRepository->find($row->getPrimaryFieldValue());
But this always return the same, too. So I don't know if this is a bundle bug or a problem because I havent the id in the grid columns. But orderIdentifier is unique, too. So if I change the workaround to this it works.
$order = $orderRepository->findByOrderIdentifier($row->getPrimaryFieldValue());
👍
Maybe this helps to clarify this.
Ok problem seems to be solved if I add the id column to grid and visible=false to property.
/**
* @GRID\Source(columns="id, orderIdentifier, state, pickupDate", filterable=false)
*/
class Order
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*
* @GRID\Column(visible=false)
*/
private $id;
}
But then it is a bug I think. But the workaround is much better than before 👍
@Bubelbub it's not a bug, a design decision actually. We will solve near future.