Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DoctrineBridge][PropertyInfo] Added support for Doctrine Embeddables#23023
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
"doctrine/orm": "^2.5" only
| return; | ||
| } | ||
| $expectedTypes = [newType( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
please use array() instead of []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
thank you, changed PHP version to 5.3 in PhpStorm for this project and fixed declaration
vudaltsov commentedJun 1, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Suddenly I faced another problem with embeddables. When an entity has properties with embeddables, /** * @ORM\Entity */class DoctrineWithEmbedded{/** * @Id * @Column(type="smallint") */public$id;/** * @Embedded(class="DoctrineEmbeddable") */protected$embedded;}/** * @ORM\Embeddable */class DoctrineEmbeddable{/** * @Column(type="string") */protected$field;}$container->get('doctrine.orm.default_entity_manager.metadata_factory') ->getMetadataFor('DoctrineWithEmbedded') ->getFieldNames();// returns['id','embedded.field',]; Fixed |
| publicfunctiontestGetEmbeddableProperties() | ||
| { | ||
| if (!class_exists('Doctrine\ORM\Mapping\Embedded')) { | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You should put$this->markTestSkipped() with message that embedded is not available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you, fixed this!
| publicfunctiontestExtractEmbeddable() | ||
| { | ||
| if (!class_exists('Doctrine\ORM\Mapping\Embedded')) { | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Same here.
vudaltsov commentedJun 11, 2017
@nicolas-grekas, anything else needed here? could it be merged? |
dunglas commentedJun 14, 2017
This should be merged in 3.4 (it's a new feature, not a bug fix). |
dunglas left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nice improvement! I just left some minor comments.
| $properties =array_merge($metadata->getFieldNames(),$metadata->getAssociationNames()); | ||
| if (class_exists('Doctrine\ORM\Mapping\Embedded')) { | ||
| if ($metadatainstanceof ClassMetadataInfo &&count($metadata->embeddedClasses) >0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
&& $metadata->embeddedClasses will be faster.
| returnarray_merge($metadata->getFieldNames(),$metadata->getAssociationNames()); | ||
| $properties =array_merge($metadata->getFieldNames(),$metadata->getAssociationNames()); | ||
| if (class_exists('Doctrine\ORM\Mapping\Embedded')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
As we'll merge this PR in 3.4, you can import this class and doclass_exists(Embedded::class).
| )); | ||
| } | ||
| if (class_exists('Doctrine\ORM\Mapping\Embedded')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
same here, same in tests.
vudaltsov commentedJun 14, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@dunglas, the problem is that now when you do $container ->get('doctrine.orm.default_entity_manager.property_info_extractor') ->getProperties(DoctrineWithEmbedded::class);// the class from my example above you receive ['id','embedded.field',// but not `embedded`]; which is not what developer might expect. So it appears that currently 2.8 doesn't fully support ORM, which might lead to unexpected behaviour. Isn't it a bug? |
dunglas commentedJun 29, 2017
Ok to consider it a bug fix then. 👍 ping @symfony/deciders |
vudaltsov commentedJul 13, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
anything else needed here? |
| $properties =array_merge($metadata->getFieldNames(),$metadata->getAssociationNames()); | ||
| if (class_exists('Doctrine\ORM\Mapping\Embedded')) { | ||
| if ($metadatainstanceof ClassMetadataInfo &&$metadata->embeddedClasses) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
could be merge with the previousif condition
| } | ||
| if (class_exists('Doctrine\ORM\Mapping\Embedded')) { | ||
| if ($metadatainstanceof ClassMetadataInfo &&isset($metadata->embeddedClasses[$property])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Same here, you can merge the 2 conditions.
| Type::BUILTIN_TYPE_OBJECT, | ||
| false, | ||
| $metadata->embeddedClasses[$property]['class'] | ||
| )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
could be on one line
| returnarray_merge($metadata->getFieldNames(),$metadata->getAssociationNames()); | ||
| $properties =array_merge($metadata->getFieldNames(),$metadata->getAssociationNames()); | ||
| if (class_exists('Doctrine\ORM\Mapping\Embedded') &&$metadatainstanceof ClassMetadataInfo &&$metadata->embeddedClasses) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can you call class_exists after the other tests (for perf, function calls cost more than other checks)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@dunglas, when classDoctrine\ORM\Mapping\Embedded doesn't exist,$metadata->embeddedClasses is not defined. I can only moveinstanceof check to the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ok can you do that? Then I'll merge :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@dunglas, done!
dunglas commentedJul 22, 2017
Thank you@vudaltsov. |
…Embeddables (vudaltsov)This PR was squashed before being merged into the 2.8 branch (closes#23023).Discussion----------[DoctrineBridge][PropertyInfo] Added support for Doctrine Embeddables| Q | A| ------------- | ---| Branch? | 2.8 and higher| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR |Note that [Embeddables appeared only in doctrine/orm 2.5](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/changelog/migration_2_5.html). I added class_exists checks for that.Commits-------7816f3b [DoctrineBridge][PropertyInfo] Added support for Doctrine Embeddables
Note thatEmbeddables appeared only in doctrine/orm 2.5. I added class_exists checks for that.