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.
On Sep 16, 10:52 am, Karen Tracey <kmtra...@gmail.com> wrote: > On Wed, Sep 16, 2009 at 10:15 AM, PlanetUnknown > <nikhil.kodil...@gmail.com>wrote: > > > > > For example - User HAS "Contacts"; User HAS "Preferences" > > Usually (I'm from an Oracle/Java background) the Contacts table would > > have a "user-id" foreign key. > > However Django models refer Foreign Key relations as "Many-to-one", > > but that is not true in my case. > > Why is it not true in your case? You say 'User HAS "Contacts", thus it > sounds like Many different Contact instances may be associated with one > single User. Many-to-One. If a user can only have a single Contact then > you might want OneToOne, but you have said in a follow up message to that > suggestion that that is not what you want. So I am having a hard time > understand what it is, exactly, that you do want. > > > There is only one Contact table for a User and it might keep growing > > as new fields are added. > > What do you mean by fields? Fields in a Django model correspond to columns > in the database table, and you generally do not want those to be growing > over time. If you mean rows in the table, then again, it sounds like you > want the many-to-one relation provided by ForeignKey. > > The "for a User" clause on your first sentence also sounds a bit wrong. > Normally, there is only one Contact table, period. Which user is associated > with a given row in the table would be determined by the value of the User > column in the table. > > Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---