EC-CUBEで複数のテーブルにまたがるようなやや複雑なカスタマイズを行っている際、次のようなエラーが発生することがあります。

Doctrine\ORM\ORMInvalidArgumentException: A new entity was found through the relationship 'Eccube\Entity\HogeEntity#ProductClass' that was not configured to cascade persist operations for entity: Eccube\Entity\ProductClass@00000000023cfc1c0000000000000000. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Eccube\Entity\ProductClass#__toString()' to get a clue. (uncaught exception) at /vendor/doctrine/orm/lib/Doctrine/ORM/ORMInvalidArgumentException.php line 91

このエラーが発生する理由は、あるEntityの追加や変更を保存(flush)しようとした時に、Doctrineのリレーションで繋がっているEntityがpersistされていない場合に発生します。

回避方法としてリレーションにcascade={“persist”}を付けておくという方法があります。

cascade={“persist”}が付与されている例

/**
* @var \Eccube\Entity\Order
*
* @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="Shippings", cascade={"persist"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="order_id", referencedColumnName="id")
* })
*/
private $Order;
日本発!ECオープンプラットフォーム「EC-CUBE」 EC-CUBEゴールドパートナー EC-CUBEは株式会社イーシーキューブの商標です

EC-CUBEカスタマイズに関するお問い合わせはこちら


    [重要]現在公式にセキュリティサポートが切れていないPHPは8.1以上、MySQLは8.0以上で、対応しているEC-CUBEバージョンは4.2以上です。古いEC-CUBEを使っている方は適切なタイミングでバージョンアップをご検討ください。

    EC-CUBEバージョンアップ