-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Provide the ability to use existing entities in commands for cascading persistence of state aggregate. #307
Comments
Current possible solution: |
Can you provide PR with failing scenario? |
Hi. I will add code snippets describing the problem. After clear all existing in database entities doctrines are perceived as new and their insertion and binding occurs, instead of just binding to the aggregate |
So the case is that when we've main Entity (Aggregate Root) like @lifinsky do I understand the problem correctly? |
No, existing tag was saved but as new record (doctrine allows cascade: ['persist']):
I think we should clear only agregates in unit of work. Entity manager supports clear($entityName = null) - null|string $entityName – if given, only entities of this type will get detached. |
Currently for this example we should find tag in interceptor with pointcut "before" on CommandHandler (after transaction start) |
So the problem is that we create @lifinsky is this understanding correct? |
Problem in using of existing entity, with current functionality of Ecotone we should inject tag repository to aggregate class or use command handler interceptor that find entity by id and fill attribute in command or return new command object (command is ugly with default arguments with null, for example int $tagId = null, Tag $tag = null. We should not clear entities in unit of work before command transaction |
I think, it's fine to set up clearing after, as long as we can clean with each Message, we are good. |
I'm running into this same issue. Did anything get sorted in the end as the last comment is quite a while ago and I can't find any related PR. Thanks |
This issue is actual and not resolved |
Description
In aggregates, it's possible to use, for instance, Doctrine entities with cascading persistence, but only for their insertion. Because ObjectManagerInterceptor clear object manager on transaction start.
Example
The only way to correctly save an aggregate with a one-to-many or many-to-many collection of entities is to inject the repository into the command handler of the aggregate or to use a "Before" interceptor that adds entities into the command before passing it to the handler.
The text was updated successfully, but these errors were encountered: