2

Scenario: I have two entities. Product & ProductGroup. Product has many to one relation to ProductGroup. I soft delete the ProductGroup. Then I try to call getProductGroup on a product which has a product group which was soft deleted.

Problem: instead of expected null result I get an "Message: Entity was not found." exception message.

$productGroupName = $product->getProductGroup() !== null ? $product->getProductGroup()->getName() : '';

1 Answers1

1

It is because of proxies Doctrine2 was generating, not the case with soft-deletable though I'm using that. But in entities where this soft-deleteable wasn't implemented i was having the same issue. so what fixed for me is Adding fetch="EAGER" on Entities Annotations where relation was defined. like

/**
 * @var \ReisesparerAPIs\Entity\Vouchers
 *
 * @ORM\OneToOne(targetEntity="ReisesparerAPIs\Entity\Vouchers", inversedBy="couponOrder", fetch="EAGER")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="voucher_id", referencedColumnName="id")
 * })
 */
private $voucher;

Reference Link

Zoe
  • 27,060
  • 21
  • 118
  • 148