In the Rails ActiveRecord Associations guide, I'm confused over why the tables for has_one
and has_many
are identical:
customers(id,name)
orders(id,customer_id,order_date)
Example tables for has_one
:
these tables will, at the database level, also allow a supplier to have many accounts, but we just want one account per supplier
suppliers(id,name)
accounts(id,supplier_id,account_number) #Foreign Key to supplier here??
Shouldn't the tables for has_one
be like this instead:
suppliers(id,name,account_id) #Foreign Key to account here
accounts(id,account_number)
Now because the account_id
is in the suppliers table, a supplier can never have more than one account.
Is the example in the Rails Guide incorrect?
Or, does Rails use the has_many
kind of approach but restricts the many
part from happening?