On Wed, Sep 16, 2009 at 1:01 PM, PlanetUnknown <nikhil.kodil...@gmail.com> wrote: > > Thanks Karen. > Let me explain it a bit more. > e.g. > All CONTACT details are present in one table - email, home address, > work address, home phone, work phone etc. > Forget about the statement about growing for now. > Since each user "has-a" contact it is a pure one-to-one relationship > and not a one-to-many or many-to-one; each user in the USER table will > have only one corresponding entry in the CONTACT table. > Does this help explaining the issue ? > The above is just an example, the main question is how does one > usually implement a "has-a" relationship in dJango.
i think a big part of your problem is that you're using java-inspired OOP terminology. it's much easier if you use RDBMS terminology (after all, it will all be stored in a RDBMS). I guess that the Oracle/Java systems you're used to show the DB as a persistence system for objects, while Django's ORM creates classes that represent the DB. same thing, different philosophies. the many-to-one relationship is exactly what you said you used in Oracle: a user-id field on the Contact table. the one-to-one relationship is the same thing, but with an added UNIQUE constraint on that key, so that you can have only one contact for each user. it has nothing to do with inheritance. the fact that inheritance is implemented with one-to-one relationships is just incidental. in most cases, you want the possibility of several contacts per user, so you can use the many-to-one. the only drawback if that you get an extra step to go from user to contact: "User.contact_set.all()". if you use one-to-one, the ORM lets you skip that step and write simply "User.contact". -- Javier --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---