monro / doctrine-nullable-embedabbles
Workarround to the issues related of using Doctrine with embedabbles relations where the relation can be null. If the object is null doctrine would instanciate it with all the properties to null, this library will fix it to set it to null.
Installs: 5 065
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 2
Requires
- php: ^7.4 || 8.0.0
- doctrine/common: ^3
- doctrine/orm: ^2
- symfony/finder: >= 4.0
- symfony/yaml: >= 4.0
Requires (Dev)
README
Why
The purpose of this library is to fix a known bug on doctrine where you cannot have nullable embeddables.
The issue is the following:
Given a class "A" that has an ORM relation with an embedded "B" that could be null
When an instance of "A" is loaded from DB and "B" is null
Then an instance of "B" is created with all the values to null and assigned to the property "B" of "A"
The behaviour of this library will be the following:
Given a class "A" that has an ORM relation with an embedded "B" that could be null
When an instance of "A" is loaded from DB and "B" is null
Then the property "B" of "A" is set to null
For now it only works with yml files as is what we use, if you think that will be useful to have it for XML or annotations, please open an issue
Installation
This library is mainly though to be used with symfony as it depends on its configuration files.
Syfmony
In your services.yaml (normally located at /config) Add this line:
imports: - { resource: ../vendor/monro/doctrine-nullable-embedabbles/src/EmbeNulls/config/services.yaml }
And if you need to change the doctrine.yaml location from the default one (%kernel.project_dir%/config/packages/doctrine.yaml
), you can set the env variable DOCTRINE_CONFIG_FILE
in your .env
Usage
Define your orm mappings as usual in your YML files and on the embedded property add nullable to true wherever you want. For instance:
#Dog.orm.yml Some\Namespace\Dog: type: entity table: dog id: ... fields: name: type: string embedded: petIdentificationNumber: class: Some\Namespace\PetIdentificationNumber nullable: true