-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
ODM double properties for ORM mapping #750
Comments
The difference is that you have a mapped field stored in mongo ( Doing cross-data-mapper references cannot be achieved exactly like references handled by the data-mapper itself. It would require to implement hooks deep inside Doctrine loading and change-tracking logic (which would be a huge performance killer for something used only in a few specific use cases) |
I tried your code @Devlopnet . But persisting the Document does not set the mapped field. I guess I am missing some kind of configuration to make my server aware of the |
Here is my full example using the Is any PR related to this issue and able to solve it resp. call the |
👍 |
@webdevilopers no it cannot. Doctrine only looks at mapped fields to decide whether the event listener is called or not when flushing |
About your answer here @stof : #750 (comment) I'm currently maintaining a project strictly following Domain Model policy in Domain-driven design. Is it possible to use a Listener in these cases that could indeed work with the same field? |
As you can see @stof I was able to create a listener that uses the same field Though this works if I understand you right this will cause problems when persisting changes? |
@webdevilopers using the same property is a bad idea, as the ORM will see a change in the property. Having the same property storing 2 different data over time is not a clean design |
Of course that makes sense @stof. Not sure if you had the time to follow our discussion here: I guess then the only alternative is to use some kind of Doctrine Wrapper around clean |
@webdevilopers another solution would be to design your model in a way acknowledging that customers and orders live in different stores and so cannot be accessed from each other directly. Your order would then contain a customerId property holding a CustomerId value object (which is just wrapping an id or a uuid or whatever else you want), and then code wanting to get full info about the customer would ask the customer repository to give it the customer for this id. In the case you describe in the issue, I may even have a Customer object in the order, which would be responsible for holding the customer from the PoV of the order context, i.e. the id I talked above as well as the address and name stored in mongo (the historical data), as this is really a Customer object here, which is different from the one you have in mysql (even if they share an id linking them together). |
I see @stof we have similar ideas of different approaches. My first workaround indeed was using The Document was then called I'm still afraid of a "native" call / use case on a |
For instance a simple P.S. @stof : http://atlantic18.github.io/DoctrineExtensions/schemas/orm/doctrine-extensions-3.0.xsd namespace Acme\AppBundle\Entity;
class Customer
{
/**
* @Gedmo\ReferenceMany(type="document", class="Acme\DomainModel\Order", mappedBy="customer")
*/
private $orders;
} <field fieldName="customerId" type="integer" />
<gedmo:reference type="entity"
class="Acme\AppBundle\Entity\Customer"
inversed-by="orders" identifier="customerId" /> namespace Acme\DomainModel;
class Order
{
private $customer;
private $customerId;
} |
What would be an analog for ReferenceMany in case a document has many ORM entities relation? Not sure if it should look like this (doesn't work)
Is there a way you can tell doctrine to load referenced ORM collection? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi,
This is not a bug but a possible improvement :
I have a User Document who has a Customer Entity reference. Code is like this :
I don't understand why i have to create two properties for that. When i set $customer, i have to set $customerId with the good value to avoid difference. The plugin should be able to map $customer with mongo property customerId without use document property $customerId. Same working as native orm mapping :)
I repeat me : it's not critical, it's perhaps hard to do, but i think it's better.
Thanks
The text was updated successfully, but these errors were encountered: