Answer the question
In order to leave comments, you need to log in
Check if related doctrine entity exists in twig?
The root entity has
/**
* @var \Backend\SalesBundle\Entity\SalesOrder
*
* @ORM\OneToOne(targetEntity="Backend\CatalogBundle\Entity\CatalogProduct")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="product_id", referencedColumnName="product_id")
* })
*/
private $product;
{{ item.product.productId }}
{{ item.product.name }}
Answer the question
In order to leave comments, you need to log in
After digging through the Internet, it turned out that an elegant solution, apparently, does not exist.
As a result, it was written to do this:
public function getProduct()
{
try {
$sku = $this->product->getSku();
} catch (\Doctrine\ORM\EntityNotFoundException $e) {
return null;
}
return $this->product;
}
/**
* @var \Backend\SalesBundle\Entity\SalesOrder
*
* @ORM\ManyToOne(targetEntity="Backend\CatalogBundle\Entity\CatalogProduct", fetch="EAGER")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="product_id", referencedColumnName="product_id")
* })
*/
private $product;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question