mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Composite key override pre generated id value #6497
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 @mathroc on GitHub (Jul 6, 2020).
Bug Report
Summary
I have a one-to-many relation between a freelance and its organizations and a one-to-one between a freelance and one of its organizations (to define the default one)
freelance ids are pre generated (uuid) but organization ids are not (postgres sequence)
when trying to insert a new freelance I generate an uuid but it’s overridden in the
BasicEntityPersisterbecause of the defaultOrganization relationhere is part of the freelance mapping:
other findings
I’m not sure why but
$newValisnullfor thedefaultOrganizationfield inBasicEntityPersister::prepareUpdateData()this causes all of the field join column field to be null’edI don’t know if the
BasicEntityPersistershould just avoid overriding an existing non-null field with null or if it’s because$newValshould not be null in the first placemaybe related to #8141
@mathroc commented on GitHub (Jul 6, 2020):
I found out that
$newValis notnullat the start of the loop but this piece of code makes itnull: https://github.com/doctrine/orm/blob/2.7/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L652-L661at the very least existing values should not be overridden and that would be enough to fix my issue
my guess is that the end goal should be to compute
$newValIdeven if the target entity is not persisted yet, then, if the column is non nullable it should be set in$result(to handle deferred foreign key)@beberlei commented on GitHub (Jul 6, 2020):
This mapping is invalid, you cannot define the same column twice.
@mathroc commented on GitHub (Jul 6, 2020):
doctrine:schema:validatesays:should I open another issue for this ?
and, is there a way to fix this mapping ?
I could add an id to
App\Domain\Model\Freelance\Organizationand use this instead of the composite key, but having the primary key inside the composite key makes it impossible to set an organization from another freelance the default organization@mathroc commented on GitHub (Aug 17, 2020):
ping @beberlei