There is no verification of the availability of the property in the bi-directional association #5811

Closed
opened 2026-01-22 15:18:34 +01:00 by admin · 1 comment
Owner

Originally created by @Sharoff45 on GitHub (Dec 18, 2017).

Originally assigned to: @Ocramius on GitHub.

I made a error in OneToMany association and received a notice when persist entity:
Undefined index: ItemEntities
File: /opt/project/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Line: 1768

OwnerEntity.php

<?php 
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 */
class OwnerEntity 
{
    /**
     * @ORM\OneToMany(targetEntity="ItemEntity" mappedBy="itemEntities", cascade={"persist"})
     *
     * @var ItemEntity[]|ArrayCollection
     */
    private $itemEntities;
}

ItemEntity.php

<?php 
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 */
class ItemEntity 
{
    /**
     * @ORM\ManyToOne(targetEntity="OwnerEntity", inversedBy="itemEntities")
     *
     * @var OwnerEntity
     */
    protected $ownerEntity;
}

I got this error only with persist.

Package: doctrine/orm v2.5.12
Dist url: 984535cadc

Originally created by @Sharoff45 on GitHub (Dec 18, 2017). Originally assigned to: @Ocramius on GitHub. I made a error in OneToMany association and received a notice when persist entity: Undefined index: ItemEntities File: /opt/project/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php Line: 1768 **OwnerEntity.php** ```php <?php use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() */ class OwnerEntity { /** * @ORM\OneToMany(targetEntity="ItemEntity" mappedBy="itemEntities", cascade={"persist"}) * * @var ItemEntity[]|ArrayCollection */ private $itemEntities; } ``` **ItemEntity.php** ```php <?php use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() */ class ItemEntity { /** * @ORM\ManyToOne(targetEntity="OwnerEntity", inversedBy="itemEntities") * * @var OwnerEntity */ protected $ownerEntity; } ``` I got this error only with persist. Package: doctrine/orm v2.5.12 Dist url: https://api.github.com/repos/doctrine/doctrine2/zipball/984535cadc609e9eef8c89414aa3568ee97aa79f
admin added the Invalid label 2026-01-22 15:18:34 +01:00
admin closed this issue 2026-01-22 15:18:34 +01:00
Author
Owner

@Ocramius commented on GitHub (Dec 18, 2017):

As the title says:

There is no verification of the availability of the property in the bi-directional association

It is up to you to make sure the property is set for OwnerEntity#$itemEntities: the ORM merely attempts to store what you provided to it.

Also, note that the OneToMany side is never the owning side of the association.

@Ocramius commented on GitHub (Dec 18, 2017): As the title says: > There is no verification of the availability of the property in the bi-directional association It is up to you to make sure the property is set for `OwnerEntity#$itemEntities`: the ORM merely attempts to store what you provided to it. Also, note that the `OneToMany` side is never the owning side of the association.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5811