Polymorphic in DBML?

I dont know how to design a polymorphic table in dbdiagram (DBML). Am I miss something or polymorphic still not there yet?

Hi Skyler,

Polymorphism is a central concept in OOP, and there are many ways to represent it when mapping then into database tables. Can you provide an example of your design and what you want to achieve through polymorphism?

I dont think this so far earlier. Example can simple as “a comment” can belong to “users”/“admin”. Thank for your help!

Hi Skyler,

Here is one way to model your example in dbml

table user {
  id int [pk]
}

table admin {
  id int [pk]
}

table comment {
  id int [pk]
  commenter_id int
  commenter_type text
  comment_text text
}

Another way is

table user {
  id int [pk]
}

table admin {
  id int [pk]
}

table comment {
  id int [pk]
  admin_id int
  user_id int 
  comment_text text
}


Ref: "admin"."id" < "comment"."admin_id"

Ref: "user"."id" < "comment"."user_id"

I hope this will help.

1 Like