Design patterns·Objects and the database between them
you changed four objects and called save once, and it worked out the order the writes had to happen in.
Unit of work
Also calledunit of work pattern, change tracker, session
An object that tracks everything changed during a business transaction and coordinates writing it out, including ordering and concurrency checks. It is what a session or context in an ORM is, and it is why calling save on one object can produce eight statements. Its two consistent surprises are the flush that happens earlier than you expected, and the fact that a long-lived unit of work is a long-lived pile of tracked state.