Skip to content

Commit 8b564fd

Browse files
fishbone1OskarStark
authored andcommitted
Update associations.rst
Added caution block that informs about the risks of generated convenience "add" and "remove" methods on the inverse side.
1 parent f104d72 commit 8b564fd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

doctrine/associations.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,15 @@ also generated a ``removeProduct()`` method::
581581
Thanks to this, if you call ``$category->removeProduct($product)``, the ``category_id``
582582
on that ``Product`` will be set to ``null`` in the database.
583583

584+
.. warning::
585+
586+
Please be aware that the inverse side could be associated with a large amount of records.
587+
I.e. there could be a large amount of products with the same category.
588+
In this case ``$this->products->contains($product)`` could lead to unwanted database
589+
requests and very high memory consumption with the risk of hard to debug "Out of memory" errors.
590+
591+
So make sure if you need an inverse side and check if the generated code could lead to such issues.
592+
584593
But, instead of setting the ``category_id`` to null, what if you want the ``Product``
585594
to be *deleted* if it becomes "orphaned" (i.e. without a ``Category``)? To choose
586595
that behavior, use the `orphanRemoval`_ option inside ``Category``:

0 commit comments

Comments
 (0)