views:

74

answers:

1

Say I have four pair-wise M2M related models: A, B, C, D. I have created an intermediary model ABCD to establish relationships between them. If there are many duplicate column pairs in the database, is it a normal practice to normalize the intermediary model into multiple models?

What I am concerned about are: 1. Breaking down ABCD will clutter the models.py 2. Are multiple 2-column tables better than a four column table (w/ duplicate column pairs)?

A: 

A few more questions that might help with your design.

  1. are all the tables related to each other?
  2. do all have to exist at the same time? Meaning, if A exists do B,C and D also exist?
  3. what are their relationships? Meaning, one to many, one to one...etc

I think what you are doing is okay, but I would be more inclined to use multiple 2 column tables (but that depends entirely on your answers to my three questions). I think the 2 column intersect tables make for easier queries and data integrity control.

EDIT (after your response):

After further review of this I think the approach that will be easier for queries etc will be the single 4 column table. I don't normally like this approach but if your data is in fact all related and will all exist you will save yourself much time with querying the data using your first approach.

I have to apologize to my DBA friends on this recommendation ;)

northpole
I've edited my question. 1: yes. 2: not for now. But with a growing database, all should exist. I am allowing the FK to be null. 3: My current design is all M2M. Thanks.
Dingle
Yes, indeed I find it will save me much work using a single table, especially when I want to output something hierarchical like A: B :C
Dingle