【发布时间】:2010-10-17 14:02:53
【问题描述】:
在 Rails ActiveRecord Associations 指南中,我对为什么 has_one 和 has_many 的表相同感到困惑:
customers(id,name)
orders(id,customer_id,order_date)
Example tables for has_one:
这些表在数据库级别还允许供应商拥有多个帐户,但我们只希望每个供应商一个帐户
suppliers(id,name)
accounts(id,supplier_id,account_number) #Foreign Key to supplier here??
has_one 的表格不应该是这样的吗:
suppliers(id,name,account_id) #Foreign Key to account here
accounts(id,account_number)
现在因为account_id 在供应商表中,供应商永远不能拥有多个帐户。
Rails 指南中的示例不正确吗?
或者,Rails 是否使用 has_many 类型的方法但限制 many 部分发生?
【问题讨论】:
标签: ruby-on-rails activerecord associations