Forum: Ruby on Rails How do I chose a table to contain a foreign key for one-to-o

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7b0233f71d74f7d0314de24aa65b7b5c?d=identicon&s=25 Leonid Raiz (lraiz)
on 2006-12-31 00:40
(Received via mailing list)
Are there some fundamental database considerations for selecting which
side of one-to-one relationship should store foreign key? This question
does not come up in one-to-many relationships but what are the
considerations in one-to-one case?

Let say for example that in my RoR application I have models for
purchase order and invoice. Do I select that Order has_one Invoice and
Invoice belongs_to Order or do I swap has_one/belongs_to usage? Both
options provide me with methods to access order from invoice and visa

Given the fact that placement of belongs_to corresponds to a table
which contains foreign key the equivalent question is how one decides
to put order_id foreign key into Invoices table or invoice_id into
Orders table? How much does it really matter which option I go with?
This topic is locked and can not be replied to.