mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Tutorial clarification - why does it work without the mapped entity's methods? #5293
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @bitwombat on GitHub (Oct 13, 2016).
I inherited a project with a OneToMany relation that didn't have any methods for setting the 'many' holder (e.g. 'reportedBugs' in User.php of the tutorial).
Out of curiosity, I cloned the tutorial and removed the assignedToBug() and addReportedBug() calls from src/Bug.php, and everything still appears to work. If I grab a User repository and ask it to get assignedBugs, they're there, as are any new ones I create with create_bug.php.
In fact, the property seems to keep up-to-date even if I create a new bug and list a User's bugs in the same php process!
Apparently doctrine is doing some magic behind the scenes that's new since the tutorial was written?
@coudenysj commented on GitHub (Oct 13, 2016):
@bitwombat In the Bug mapping, we define
@ManyToOne(targetEntity="User", inversedBy="assignedBugs").The assignedToBug() and addReportedBug() have nothing to do with the fact that (if you grab a user from the repository) the list of reportedBugs gets filled.
@bitwombat commented on GitHub (Nov 4, 2016):
Thanks @coudenysj . I get (from the docs) that only changes to the many side cause an update to the db. Since my experiment described above works, I can only assume that the syncing functions (e.g. assignedToBug() and addReportedBug()) are there to keep the objects in sync when in memory changes occur. Is that correct?