Map entity relationships #132
betelgense
started this conversation in
General
Replies: 1 comment 4 replies
-
In case of Article and Tag, only Article is an aggregate root, tag is just an Entity.
You are thinking of domain entities as database tables. You shouldn't. Your domain entities are not tables and should be designed differently. Domain model could look like this: // user domain entity/aggregate
class User {
id: string;
// ... rest
} // wallet domain entity/aggregate
class Wallet {
id: string;
userId: string; // you most likely don't need an actual relation here, just a user id
// ... rest
} Database model: CREATE TABLE users (
id CHARACTER VARYING PRIMARY KEY NOT NULL,
-- rest
); CREATE TABLE wallets (
id CHARACTER VARYING PRIMARY KEY NOT NULL,
user_id CHARACTER VARYING
-- rest
);
-- add relation on the database level
alter table "wallets" add constraint "wallet_user_id_fk" foreign key ("user_id") references "users" ("id") |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If I have two aggregate root "article" & "tag" and I need to have a relationship by composition having the direct reference how it should be modeled
class Article {
// ...
tag: Tag; // Direct reference to a Tag entity
}
Can anyone provide a minimal example if I were to change the business rules to that a user can have 1...n wallets and a wallet can have 1...n users
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions