Skip to content

MappedSuperclass with embeddables#132

Closed
Zales0123 wants to merge 2 commits into
Sylius:masterfrom
Zales0123:mappedsuperclass-with-embeddables
Closed

MappedSuperclass with embeddables#132
Zales0123 wants to merge 2 commits into
Sylius:masterfrom
Zales0123:mappedsuperclass-with-embeddables

Conversation

@Zales0123

@Zales0123 Zales0123 commented Apr 30, 2019

Copy link
Copy Markdown
Contributor

Problem

It was detected on both this and some other plugin. If entities mapping are changed to mapped-superclass, embeddable relations are not resolved at all (columns are not added to entities' tables). This is, of course, a pity, as embeddables are highly useful for resolving some problems.

My first thought was that our ORMMappedSuperClassSubscriber from ResourceBundle is doing something wrong, but I've realized that class metadata passed to its loadClassMetadata function already has embeddable columns set (or not set in our case).

Idea

The problem is in this line from doctrine/orm package. Apparently, mapped superclasses are not meant to be used with embeddables for some reason :/ Our subscriber is converting mapped superclasses to entities (with convertToEntityIfNeeded function) but it listens to loadClassMetadata which is thrown after embeddables resolving 🚀 At the end, the best idea is to use convertToEntityIfNeeded function before processing embeddables, but after loading metadata for class.

Solution

I've decorated the MappingDriverChain class to throw an event just after metadata is loaded for a class (which is still before resolving embeddables) and overwritten the ORMMappedSuperClassSubscriber to listen to this event and do the same as for loadClassMetadata event. It works 🎉 but has some drawbacks:

The separated question is, if this fix is correct, where should it be done? I believe we should fix it in Sylius, but I open a PR here to show that this is working and to not litter the main Sylius repo with some potentially invalid solution 😄

I need your help and opinion very much, to see if it's in any part the way we want to go to fix this frustrating problem 🖖

cc @pamil @lchrusciel @bartoszpietrzak1994 @kortwotze

@Zales0123 Zales0123 added Bug Confirmed bugs or bugfixes. RFC Discussions about potential changes or new features. labels Apr 30, 2019
@Zales0123 Zales0123 requested a review from a team as a code owner April 30, 2019 11:12
@Zales0123 Zales0123 force-pushed the mappedsuperclass-with-embeddables branch 2 times, most recently from e447893 to 09d17d1 Compare April 30, 2019 11:31
return $this->baseMappingDriverChain->getAllClassNames();
}

public function isTransient($className)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could add return type

@Zales0123 Zales0123 force-pushed the mappedsuperclass-with-embeddables branch from 09d17d1 to 658e3eb Compare May 6, 2019 10:57
@Zales0123 Zales0123 requested a review from pamil May 6, 2019 13:05
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;

class DriverChain implements MappingDriver

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we finalize it?

@peterukena

Copy link
Copy Markdown

I will try this PR as soon as we have finalized the 1.4.x upgrade to our systems which can possibly be done this week. We will see. :) Thanks for this! ❤️

To be honest, I think this is not resolving any broken things, but rather adding a lot of convenience for developers to be able to extend standard sylius entities with proper means and not overriding all mappings for a plugin.

In addition I think the solution to convert mapped-superclasses to entities before embeddables are resolved should be correct. I see no usecase right now where someone would do shenanigans in the same place of execution. :)

@pamil

pamil commented Jun 7, 2019

Copy link
Copy Markdown
Contributor

Took this code and transformed it into Sylius/SyliusResourceBundle#89.

@Zales0123

Copy link
Copy Markdown
Contributor Author

Closing, as it should work after Sylius/SyliusResourceBundle#89 in #130

@Zales0123 Zales0123 closed this Jun 10, 2019
pamil added a commit that referenced this pull request Jun 10, 2019
…bility (kortwotze, pamil, Zales0123)

This PR was merged into the 1.0-dev branch.

Discussion
----------

Can you also please tag a version of this for Sylius 1.3?

Closes #132.

Commits
-------

8c9c28e Smaller style and code fixes
c081e0f Update the PR and use ResourceBundle ^1.6.0-RC.2
d8da4df Make CreditMemoSequence entity again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Confirmed bugs or bugfixes. RFC Discussions about potential changes or new features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants