Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DoctrineBridge] Allow to ignore specific nullable fields in UniqueEntity #49293

Merged
merged 1 commit into from May 19, 2023

Conversation

VincentLanglet
Copy link
Contributor

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #...
License MIT
Doc PR symfony/symfony-docs#... TODO

When the UniqueEntity is applied on multiple things the only option was

  • ignore all nullable values
  • do not ignore any nullable values

With this feature, it would be possible to ignore nullable values for specific field only and do not ignore nullable values for others.

@carsonbot
Copy link

Hey!

I think @malarzm has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@VincentLanglet
Copy link
Contributor Author

Hi @nicolas-grekas, Would you have some time to review this PR ?
Thanks a lot

@VincentLanglet
Copy link
Contributor Author

Hi @fabpot maybe you have some time to take a look or redirect me to the right reviewer ?

Thanks

Copy link
Contributor

@malarzm malarzm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly I have a hard time figuring out a use case for this. Could you please share one?

@VincentLanglet
Copy link
Contributor Author

Frankly I have a hard time figuring out a use case for this. Could you please share one?

I have an entity of UserRoles which are related to

  • An Organization
  • A Project
  • A User
  • An email

For a specific Organization and Project, only one UserRole should exists.
But UserRole with no relation to a project can exists, it will be only related to a Project, it's only allowed one time.
And the User is nullable, because it's not set until the email is validated.

For the same User/Organization, you cannot have multiple null project
but for the same Organization/Project, you can have multiple null user (pending)

UniqueEntity(fields={organization, project, user}, ignoreNull={user})

Copy link
Contributor

@malarzm malarzm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the use case, it makes more sense now!

@VincentLanglet
Copy link
Contributor Author

Would you have time to take a look/review this @nicolas-grekas @fabpot ?
Thanks a lot !

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nicolas-grekas nicolas-grekas changed the title [Doctrine-bridge] Allow to ignore specific nullable fields in UniqueEntity [DoctrineBridge] Allow to ignore specific nullable fields in UniqueEntity May 19, 2023
@nicolas-grekas
Copy link
Member

Thank you @VincentLanglet.

@nicolas-grekas nicolas-grekas merged commit 95aa09e into symfony:6.3 May 19, 2023
4 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants