A one-to-one association, or, more correctly, a pair of 0 or one-to-one associations, is implemented by a foreign key reference to at most one record in another table, and the following figure describes the relationship between the Orders table and the Invoices table:
In an active record, to represent such a relationship requires adding a Has_one:invoice declaration to the Order class and adding a declaration Belongs_to:order in the invoice class, in fact, we can think of this association as Mutual, We can make invoice have an order, or we can have a invoice for the order, but when we store the object in the database, if we give an object a Has_one association to another existing object, the associated object will be saved automatically. For example:
An_invoice = Invoice.new (...)
Order.invoice = an_invoice # Invoice gets saved
If we give an object a belongs_to association to another object, it will not be saved automatically, for example:
Order = order.new (...)
An_invoice.order = Order # Saved
There is another difference, when you give an object a Has_one association, if you point to a surviving child object, the Foreign key Association of the existing object will be removed, that is, clear zero, the following figure: