OnToMany reflexive relationship #5148

Closed
opened 2026-01-22 14:59:42 +01:00 by admin · 2 comments
Owner

Originally created by @ajax13 on GitHub (Jun 10, 2016).

Hello,

How can I make a OneToMany for a reflexive association?

reflexive relationship

Class A{
/**
@ORM\OneToMany(targetEntity="A", mappedBy="A")
**/
private $arrayOfA
}

Thanks!

Originally created by @ajax13 on GitHub (Jun 10, 2016). Hello, How can I make a **OneToMany** for a reflexive association? ![reflexive relationship](https://cloud.githubusercontent.com/assets/2513194/15968209/465da42a-2f2b-11e6-9d0d-aea777e27753.gif) > Class A{ > /** > @ORM\OneToMany(targetEntity="A", mappedBy="A") > **/ > private $arrayOfA > } Thanks!
admin closed this issue 2026-01-22 14:59:43 +01:00
Author
Owner

@JCMais commented on GitHub (Jun 10, 2016):

class Node
{
    /** @ORM\Id 
     * @Column(type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

    //...

    /**
     * @ORM\ManyToOne(targetEntity="Node", inversedBy="children")
     */
    protected $parent;

    /**
     * @ORM\OneToMany(targetEntity="Node", mappedBy="parent")
     */
    protected $children;
}
@JCMais commented on GitHub (Jun 10, 2016): ``` php class Node { /** @ORM\Id * @Column(type="integer") * @ORM\GeneratedValue(strategy="IDENTITY") */ protected $id; //... /** * @ORM\ManyToOne(targetEntity="Node", inversedBy="children") */ protected $parent; /** * @ORM\OneToMany(targetEntity="Node", mappedBy="parent") */ protected $children; } ```
Author
Owner

@ajax13 commented on GitHub (Jun 10, 2016):

Thank you so much for your swift reply!

@ajax13 commented on GitHub (Jun 10, 2016): Thank you so much for your swift reply!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5148