Tutorial clarification - why does it work without the mapped entity's methods? #5293

Closed
opened 2026-01-22 15:03:46 +01:00 by admin · 2 comments
Owner

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?

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?
admin closed this issue 2026-01-22 15:03:46 +01:00
Author
Owner

@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.

@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.
Author
Owner

@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?

@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?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5293