mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Use query expression in indexBy. #6145
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 @I70l0teN4ik on GitHub (Dec 20, 2018).
Originally assigned to: @Ocramius on GitHub.
Feature Request
Summary
Would be very useful to pass query expression to indexBy. Especially if you have a relation to entities with a composite primary key.
Let's say we have an entity Foo with a collection of Bar. But Bar actually has a unique and potentially a primary key on: foo_id + baz_id + quux_id. So simply passing the concat expression would give a guaranteed unique index for collection inside one Foo.
This would help to avoid issues in unit of work during the update of Foo.
@ORM\OneToMany(targetEntity="Bar", mappedBy="foo", indexBy="CONCAT(baz_id, quux_id)")
@Ocramius commented on GitHub (Dec 21, 2018):
Closing as
won't fix: same reasoning as https://github.com/doctrine/doctrine2/issues/7535#issuecomment-449188277What could be done (in my opinion) is implementing surrogate read-only entity fields that are only hydrated, and never considered by the
UnitOfWork. Once that's done, this becomes a trivial operation.