Open stevro opened 4 years ago
@stevro thanks for submitting this issue.
On the first glance it seems that your mapping isn't correct, based on what you're describing.
I'd say that User
should be owning side of the association and not Schedule
.
How the ORM behaves when you invert your mapping?
If I invert the mapping it's working. But both cases should be covered in my opinion. We can't always do the queries from the owning side.
I solved the problem by creating a custom repository method for the UniqueEntity validator where I fetch only the User entity without any join.
But maybe SLC could ignore entities that are not yet persisted or have the identifier = null.
@stevro unfortunately this is not the case for covering the two mappings...
According to the ORM semantics, the one you've posted is invalid and should have triggered a mapping validation error - I'm assuming that the schema validation command didn't trigger any error.
Bug Report
Summary
Given 2 enties, User and Schedule with a One To One relation between them User can have one schedule, but it's not mandatory, so there can be users without schedule.
When updating the user, if you try to also add a schedule, it will try to save in the cache an unpersisted entity Schedule with id=null.
I mention that the error is triggered by the unique validator on User entity, when it does the select. Maybe SLC should ignore entities that don't have a valid identifier. I'll also report this to symfony validation component team.
Current behavior
With env=dev you will get a Notice:
How to reproduce
Create 2 entities with bidirectional OneToOne relation, User <-> Schedule Have a unique constraint on User (by email for ex.) Have a single form for creating both the User and Schedule. Firstly create only the User Then update the User and fill in the schedule.