Documentation clarification - bidir, OneToMany #5291

Open
opened 2026-01-22 15:03:37 +01:00 by admin · 0 comments
Owner

Originally created by @bitwombat on GitHub (Oct 13, 2016).

From the reference manual:

A one-to-many association has to be bidirectional, unless you are using an additional join-table. This is necessary, because of the foreign key in a one-to-many association being defined on the “many” side. Doctrine needs a many-to-one association that defines the mapping of this foreign key.

I know this is basic and fundamental, and I appreciate you guys' patience. But I don't follow the reasoning here.

A one-to-many association has to be bidirectional

OK, that's the statement, and what I don't understand. The rest of the paragraph is the reasoning.

This is necessary because of the foreign key in a one-to-many association being defined on the “many” side.

I understand that the FK is defined on the many side. But why does this make bidirectionality necessary?

Doctrine needs a many-to-one association that defines the mapping of this foreign key.

But, all the information is present in the "many" side:

    // ...
    /**
     * @ManyToOne(targetEntity="Product", inversedBy="features")
     * @JoinColumn(name="product_id", referencedColumnName="id")
     */
    private $product;

Why do we need the mirror image of this same information on the "one" side?

Happy to help clarify the documentation with a PR if it's not "just me" :)

Originally created by @bitwombat on GitHub (Oct 13, 2016). From [the reference manual](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-many-bidirectional): > A one-to-many association has to be bidirectional, unless you are using an additional join-table. This is necessary, because of the foreign key in a one-to-many association being defined on the “many” side. Doctrine needs a many-to-one association that defines the mapping of this foreign key. I know this is basic and fundamental, and I appreciate you guys' patience. But I don't follow the reasoning here. > A one-to-many association has to be bidirectional OK, that's the statement, and what I don't understand. The rest of the paragraph is the reasoning. > This is necessary because of the foreign key in a one-to-many association being defined on the “many” side. I understand that the FK is defined on the many side. But why does this make bidirectionality necessary? > Doctrine needs a many-to-one association that defines the mapping of this foreign key. But, all the information is present in the "many" side: ``` // ... /** * @ManyToOne(targetEntity="Product", inversedBy="features") * @JoinColumn(name="product_id", referencedColumnName="id") */ private $product; ``` Why do we need the mirror image of this same information on the "one" side? Happy to help clarify the documentation with a PR if it's not "just me" :)
admin added the Documentation label 2026-01-22 15:03:37 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5291