-
Hi! Can u explain how to implement this?
And UserBookEntity the same entity like UserEntity. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Your example is partially correct.
const userBook = userEntity.get(); // <-- returns UserBookEntity
userBook.doSomething() // <-- aggregate integrity violated You should not return child entities from an Aggregate Root (you can return it's data though if you need to, but it must be immutable). If you need to perform manipulations to child entities, do this instead: userEntity.doSomethingToBook(); // <-- method is called on UserEntity, not the it's child This way you don't cross any boundaries, no risk to execute something in a child entity that depends on a parent.
Some more rules of Aggregate Roots here |
Beta Was this translation helpful? Give feedback.
Your example is partially correct.
get()
method that returns a child entity, but it makes it possible to violate the rule like this:You should not return child entities from an Aggregate Root (you can return it's data though if you need to, but it must be immutable).
If you need to perform manipulations to child entities, do this instead: