为客户建模的最佳方式 <-->地址 [英] Best way to model Customer <--> Address
问题描述
每个客户
都有一个实际地址和一个可选的邮寄地址.您首选的建模方式是什么?
选项 1. Customer
有 Address
选项 2.Customer
与 Address
具有一对多关系,其中包含一个字段描述地址类型
选项 3. 地址信息被反规范化并存储在 Customer
我的首要目标之一是简化对象-关系映射,因此我倾向于第一种方法.你有什么想法?
出于正常化的所有常见原因,我倾向于第一种方法.这种方法还可以更轻松地对邮件详细信息执行数据清理.
如果您可能要允许多个地址(邮件、住宅等)或希望能够使用有效日期,请考虑这种方法
<前>客户(id,phys_address_id)cust_address_type(cust_id、mail_address_id、address_type、start_date、end_date)地址(身份证、街道、城市等)Every Customer
has a physical address and an optional mailing address. What is your preferred way to model this?
Option 1. Customer
has foreign key to Address
Customer (id, phys_address_id, mail_address_id) Address (id, street, city, etc.)
Option 2. Customer
has one-to-many relationship to Address
, which contains a field
to describe the address type
Customer (id) Address (id, customer_id, address_type, street, city, etc.)
Option 3. Address information is de-normalized and stored in Customer
Customer (id, phys_street, phys_city, etc. mail_street, mail_city, etc.)
One of my overriding goals is to simplify the object-relational mappings, so I'm leaning towards the first approach. What are your thoughts?
I tend towards first approach for all the usual reasons of normalisation. This approach also makes it easier to perform data cleansing on mailing details.
If you are possibly going to allow multiple addresses (mail, residential, etc) or wish to be able to use effective dates, consider this approach
Customer (id, phys_address_id) Cust_address_type (cust_id, mail_address_id, address_type, start_date, end_date) Address (id, street, city, etc.)
这篇关于为客户建模的最佳方式 <-->地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!