Skip to content

How to deal with child entities #88

Answered by Sairyss
Anxium asked this question in Q&A
Discussion options

You must be logged in to vote

Email seems like a Value Object to me, it's a property of a Member, not an entity with a separate identity. So I'd say extend ValueObject.
For saving it to the database, your memberRepo can save the email in a separate table, with the same ID as a member ID (many to one relation). When you query you just join 2 tables.

One of the most important things to understand about DDD is that your domain model is not the same as database model. You shouldn't create an entity for something just because it will be in a separate table. You can just use it as a regular value, or as a value object, and let repository decide how it wants to save it.

Replies: 5 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@Anxium
Comment options

@Sairyss
Comment options

@Anxium
Comment options

Answer selected by Anxium
Comment options

You must be logged in to vote
1 reply
@Anxium
Comment options

Comment options

You must be logged in to vote
1 reply
@Sairyss
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants