Skip to main content
← Back to index page

0️⃣ Optional Relationships in DBML

dbdiagramdbdocs

Back in Zero-to-One/Many Relationships we started drawing optional relationships, working it out from the nullable constraint on the foreign key. Now you can say it directly: add a ? to either side of a relationship operator to mark that side optional. It works with all four operators (<, >, -, <>).

Table orders {
id int [pk]
customer_id int [ref: ?> customers.id] // a customer may have no orders
coupon_id int [ref: ?>? coupons.id] // an order may have no coupon
}

New to relationship types, or want to see optional refs across one-to-one, one-to-many and many-to-many with sample data? Read the tutorial on optional relationships.

πŸ“š Read the full syntax docs β†’

Give it a try and let us know what you think.