lenny4/doctrine-merge-persistent-collection-bundle
A Symfony bundle that provides a merge-persistent Doctrine collection, helping entities keep collection state across merges and reducing unexpected orphan removals during Doctrine entity merging operations.
EntityManager::merge(). This package addresses precisely the failure point in that path: Doctrine's PersistentCollection does not merge correctly by default, producing duplicated rows, stale collection contents, or orphaned children. If your roadmap includes "full-replace" update semantics on relational collections, this is the defect class you will eventually hit.orphanRemoval, composite keys, ordering, clear-plus-re-add semantics). The value is not novel capability — it is not rediscovering edge cases. Treat this as a reference implementation to copy, not a dependency to adopt.Consider it only when all of the following hold:
merge(), orphaned children surviving an update, or cascade-merge exceptions on nested collections. If you cannot reproduce the bug, you do not need the package.orphanRemoval: true, ordered collections (@OrderBy), and bidirectional associations with mappedBy/inversedBy.doctrine/orm major (2.14+ vs 3.x — ORM 3 changed collection and UoW semantics meaningfully), doctrine/collections, and symfony/*. Do not --ignore-platform-reqs past conflicts; that converts a dependency problem into a runtime problem.Look elsewhere — or solve it differently — when:
merge() entirely. The durable fix is loading managed entities and reconciling collections explicitly against the payload. More code, but it removes a whole bug class. Prefer that pattern over patching merge().For executives (30 seconds): This is a tiny, MIT-licensed utility addressing a known sharp edge in Doctrine, the ORM used by Symfony applications. It is not a strategic capability, and it should not go into our dependency stack: one maintainer, essentially no users, no maintenance commitments, and it is not a Laravel package — if the question came up in that context, the answer is no. The recommendation is to copy the relevant logic into our own codebase if and when we hit the problem (legally fine under MIT). Cost: roughly a day of engineering plus tests. Benefit: it closes a class of data-duplication bugs on bulk-update and import endpoints without adding supply-chain risk. Low urgency.
For engineering leads: The problem is real and worth understanding — merging detached entity graphs with PersistentCollection children produces duplicate rows, dropped elements, or cascade exceptions, and hand-rolling the fix means rediscovering the same edge cases around orphanRemoval, composite keys, and ordered collections. This repo is a compact reference for exactly those cases, and its small surface area can be audited in an afternoon. Proposal: reproduce the failing scenario with a characterization test against our actual mappings, then either reimplement in application code (~50 lines) or fork under our namespace and own the release cadence. Also note the failure mode: bugs here don't throw, they corrupt — so the test suite, not the package, becomes the support contract. Do not add it to composer.json; do not --ignore-platform-reqs around Doctrine 3.x constraints; pin the ORM while any vendored code is in use.
Recommendation: Vendor, don't depend — and only if a Doctrine merge path actually exists in our codebase. Low priority; act when an import/sync surface on Doctrine next needs work.
How can I help you explore Laravel packages today?