Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed
vudaltsov wants to merge7 commits intosymfony:2.8fromvudaltsov:2.8

Conversation

@vudaltsov
Copy link
Contributor

QA
Branch?2.8 and higher
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

Note thatEmbeddables appeared only in doctrine/orm 2.5. I added class_exists checks for that.

"doctrine/orm": "^2.5" only
return;
}

$expectedTypes = [newType(

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 []

Copy link
ContributorAuthor

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

@nicolas-grekasnicolas-grekas added this to the2.8 milestoneJun 1, 2017
@vudaltsov
Copy link
ContributorAuthor

vudaltsov commentedJun 1, 2017
edited
Loading

Suddenly I faced another problem with embeddables.

When an entity has properties with embeddables,Doctrine\Common\Persistence\Mapping\ClassMetadata::getFieldNames() returns property paths for them. Example:

/** * @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',];

FixedDoctrineExtractor::getProperties() in the next commit.

publicfunctiontestGetEmbeddableProperties()
{
if (!class_exists('Doctrine\ORM\Mapping\Embedded')) {
return;
Copy link
Contributor

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.

nicolas-grekas and vudaltsov reacted with thumbs up emoji
Copy link
ContributorAuthor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

@vudaltsov
Copy link
ContributorAuthor

@nicolas-grekas, anything else needed here? could it be merged?

@dunglas
Copy link
Member

This should be merged in 3.4 (it's a new feature, not a bug fix).

Copy link
Member

@dunglasdunglas left a 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) {
Copy link
Member

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')) {
Copy link
Member

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).

fabpot reacted with thumbs up emoji
));
}

if (class_exists('Doctrine\ORM\Mapping\Embedded')) {
Copy link
Member

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
Copy link
ContributorAuthor

vudaltsov commentedJun 14, 2017
edited
Loading

@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
Copy link
Member

Ok to consider it a bug fix then. 👍

ping @symfony/deciders

@vudaltsov
Copy link
ContributorAuthor

vudaltsov commentedJul 13, 2017
edited
Loading

anything else needed here?

$properties =array_merge($metadata->getFieldNames(),$metadata->getAssociationNames());

if (class_exists('Doctrine\ORM\Mapping\Embedded')) {
if ($metadatainstanceof ClassMetadataInfo &&$metadata->embeddedClasses) {
Copy link
Member

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])) {
Copy link
Member

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']
));
Copy link
Member

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) {
Copy link
Member

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)?

Copy link
ContributorAuthor

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.

Copy link
Member

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 :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@dunglas, done!

@dunglas
Copy link
Member

Thank you@vudaltsov.

dunglas added a commit that referenced this pull requestJul 22, 2017
…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
@vudaltsovvudaltsov deleted the 2.8 branchJuly 31, 2017 19:51
This was referencedAug 1, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@dunglasdunglasdunglas approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@xabbuhxabbuhxabbuh approved these changes

+1 more reviewer

@stloydstloydstloyd approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

2.8

Development

Successfully merging this pull request may close these issues.

7 participants

@vudaltsov@dunglas@fabpot@stloyd@nicolas-grekas@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp