Iterate with fetch join in class ~ not allowed. Error correction [Symfony]

When developing with a Symfony-based EC-CUBE online shop system, I searched for solutions to the errors that occurred, so I will leave them on my blog as a memorandum.

I had to issue a little heavy SQL, so when I tried to process it with ORM iterate, the following error occurred.

Iterate with fetch join in class Eccube\Entity\ProductClass using association Product not allowed.

I found a description that leads to a solution in Git.
Iterate with fetch join in subquery

Iterate with fetch join in class ~ not allowed.Error resolution

To summarize the Git statement, distinct.
I was able to solve it by executing distinct for select.
By the way, distinct is an instruction to combine duplicate records into one.

Resolved code

$qb->select('p, pc')

$result = $qb->iterate();




The above error seems to occur when joining in the Entity to be acquired.
The actual Entity part is below.(EC-CUBE src)

 * @var \Doctrine\Common\Collections\Collection
 * @ORM\OneToMany(targetEntity="Eccube\Entity\ProductClass", mappedBy="Product", cascade={"persist","remove"})
private $ProductClasses;

This is an example of joining ProductClass in Entity/Product.php. As mentioned above, you need to distinct() if you are joining.

Leave a Reply 0

Your email address will not be published.

3 × 4 =