jorge07 / symfony-6-es-cqrs-boilerplate

Symfony 6 DDD ES CQRS backend boilerplate.
MIT License
1.06k stars 185 forks source link

Relationships example #237

Closed rtwent closed 9 months ago

rtwent commented 2 years ago

Hi. A lot of thanks for Your work. I study ddd in practice, so I try to implement relationship between domain and its entities. I struggle for few days and can not find the correct answer. Let's imagine, that our user will have the profile and address (separate entities). I have readModels, e.g. profileReadModel and addressReadModel. They are in infrastructure level of the application. So my question: can I use advantages of the doctrine relations handling in this level? Let's imagine I need something like this in response: {"user": {"id": "", "name": "", "address": {"city": "", "zip":""}, "profile": {"bio": "", "lastjob": ""}}} If address and profile of the userReadModel will have UuidInterface type (as ddd claims https://matthiasnoback.nl/2018/06/doctrine-orm-and-ddd-aggregates/) i think it will be problems with perfomance, because I have to query database for a three times to provide the response. If I'll need a 100 users there will be much more queries.

Do You have some hints for me?

arikanaydin commented 2 years ago

Hi, Wouldn't it be the right approach to solve in the reading model?

jorge07 commented 9 months ago

Sorry for take that long.

My point will be: Use embedded in infrastructure objects like here. That will eliminate the need of extra queries. Data structure is an implementation details AKA infrastructure and should serve it purpose. There perfect database design is the one that serve his purpose efficiently, I see many times tends to design schemas with no data duplication and only the theoretically needed relationships. The database is not the domain model. A table is not an entity. In some cases, and entity can live in a json column and be fine.