-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
"doctrine/orm": "^2.5" only
return; | ||
} | ||
|
||
$expectedTypes = [new Type( |
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
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 |
public function testGetEmbeddableProperties() | ||
{ | ||
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!
public function testExtractEmbeddable() | ||
{ | ||
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.
@nicolas-grekas, anything else needed here? could it be merged? |
This should be merged in 3.4 (it's a new feature, not a bug fix). |
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 ($metadata instanceof 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.
return array_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 do class_exists(Embedded::class)
.
@@ -105,6 +117,16 @@ public function getTypes($class, $property, array $context = array()) | |||
)); | |||
} | |||
|
|||
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.
@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? |
Ok to consider it a bug fix then. 👍 ping @symfony/deciders |
anything else needed here? |
$properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames()); | ||
|
||
if (class_exists('Doctrine\ORM\Mapping\Embedded')) { | ||
if ($metadata instanceof 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 previous if
condition
@@ -105,6 +117,16 @@ public function getTypes($class, $property, array $context = array()) | |||
)); | |||
} | |||
|
|||
if (class_exists('Doctrine\ORM\Mapping\Embedded')) { | |||
if ($metadata instanceof 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
return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames()); | ||
$properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames()); | ||
|
||
if (class_exists('Doctrine\ORM\Mapping\Embedded') && $metadata instanceof 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 class Doctrine\ORM\Mapping\Embedded
doesn't exist, $metadata->embeddedClasses
is not defined. I can only move instanceof
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!
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 that Embeddables appeared only in doctrine/orm 2.5. I added class_exists checks for that.