> Apart for an existing DB where a specific table handles this one-to-one > relation, what is the benefit of this method over the > belongs_to / has_one syntax ? You also get a bidirectional association, > don't you ?
You do, but it's strictly 1-1 or 1-N (in whatever direction). In other words, when you change the reference on either end, you... change the reference. With has_and_belongs_to(uselist=False), you get bidirectional (a named attribute on both models), 1-1 (each reference is singular), but each entity can have a distinct reference to some other distinct entity--that is, under the hood, an association table is still created, and the foreign key references on the entities actually refer to that association table, which in turn refers to the other entity. This prevents weird semantics (from the object-oriented perspective), where an entity can only be associated with a single other entity, and "vanishes" from the entity it was previously associated with when the reference on the parent entity is changed. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "SQLElixir" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlelixir?hl=en -~----------~----~----~----~------~----~------~--~---
