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

Make the code compatible with DBAL 3 and 4 by swithing the type when… #1685

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from

Conversation

rande
Copy link
Member

@rande rande commented May 15, 2024

Make the code compatible with DBAL 3 and 4 by swithing the type when the Mapping is loaded

I am targeting this branch, because because it introduces a non necessary BC break. For reference: #1677

Changelog

### Removed
- BaseUser3 doctrine definition

### Added
- Mapping listener to make the same entity works with DBAL 2, 3 or 4

To do

  • Review PR;

@VincentLanglet
Copy link
Member

There is the error

In MappingException.php line 112:
                                                                               
  The column type of attribute 'roles' on class 'Sonata\UserBundle\Tests\App\  
  Entity\User' could not be changed. 

@rande rande force-pushed the revert_bc_issue_with_roles branch 4 times, most recently from 6f8282e to cec9f6a Compare May 15, 2024 17:10
@rande rande force-pushed the revert_bc_issue_with_roles branch from cec9f6a to 85202a9 Compare May 15, 2024 17:12
@rande
Copy link
Member Author

rande commented May 15, 2024

@VincentLanglet hopefully this is good to go!

Comment on lines +49 to +52
/**
* @psalm-suppress InvalidPropertyAssignmentValue
*/
$metadata->fieldMappings['roles']['type'] = 'array';
Copy link
Member

Choose a reason for hiding this comment

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

Is it the right way to change the value ?

The property is documented as READ-ONLY
https://github.com/doctrine/orm/blob/3d9af3187f59930972e7fcb90a1d8059a37b8032/src/Mapping/ClassMetadata.php#L334-L339

Copy link
Member

Choose a reason for hiding this comment

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

I think

public function setAttributeOverride(string $fieldName, array $overrideMapping): void

should be used instead. (https://github.com/doctrine/orm/blob/3.1.x/src/Mapping/ClassMetadata.php#L1737)

Copy link
Member Author

Choose a reason for hiding this comment

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

@VincentLanglet https://github.com/doctrine/orm/blob/3.1.x/src/Mapping/ClassMetadata.php#L1765-L1767 it is not possible to change the type using this way.

This solution is a hack but to be honest having a second class BaseUser3 just to change the type is not good either. This can end up, with BaseUser4 etc ...

Copy link
Member

Choose a reason for hiding this comment

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

Any recommendation for such situation @greg0ire ? Is it the best way ?

@VincentLanglet
Copy link
Member

The doc need to be updated too, in order to remove reference of BaseUser3 https://github.com/sonata-project/SonataUserBundle/blob/a6169f318ad30a46ced640fad58a686e695e86f0/docs/reference/installation.rst#doctrine-orm-configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants