Skip to content

Update associations.rst #18828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doctrine/associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,15 @@ also generated a ``removeProduct()`` method::
Thanks to this, if you call ``$category->removeProduct($product)``, the ``category_id``
on that ``Product`` will be set to ``null`` in the database.

.. warning::

Please be aware that the inverse side could be associated with a large amount of records.
I.e. there could be a large amount of products with the same category.
In this case ``$this->products->contains($product)`` could lead to unwanted database
requests and very high memory consumption with the risk of hard to debug "Out of memory" errors.

So make sure if you need an inverse side and check if the generated code could lead to such issues.

But, instead of setting the ``category_id`` to null, what if you want the ``Product``
to be *deleted* if it becomes "orphaned" (i.e. without a ``Category``)? To choose
that behavior, use the `orphanRemoval`_ option inside ``Category``:
Expand Down