Skip to content
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

Relationships example #237

Closed
rtwent opened this issue May 31, 2022 · 2 comments
Closed

Relationships example #237

rtwent opened this issue May 31, 2022 · 2 comments

Comments

@rtwent
Copy link

rtwent commented May 31, 2022

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
Copy link

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

@jorge07
Copy link
Owner

jorge07 commented Oct 1, 2023

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.

@jorge07 jorge07 closed this as completed Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants