Best way to model Customer <--> Address

后端 未结 12 1703
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 02:22

Every Customer has a physical address and an optional mailing address. What is your preferred way to model this?

Option 1. Customer has fo

12条回答
  •  旧时难觅i
    2020-11-30 02:46

    Like in many cases: It depends.

    If your customers deal with multiple addresses then a to-many relationship would be appropriate. You could introduce a flag on address that signals if an address is for shipment or bill, etc. Or you store the different address types in different tables and have multiple to-one relationships on a customer.

    In cases where you only need to know one address of a customer why would you model that to-many? A to-one relationship would satisfy your needs here.

    Important: Denormalize only if you encounter performance issues.

提交回复
热议问题