1

I have to model the following entities: BuildingSite, Company, Worker.

Each entity has a many-to-many relationship with the other entities, and each relationship some attributes like start_date, finish_date, craft, contract, etc... A naive approach coul be like that:

BuildingSiteCompanyRelationship:
  - building_site: ForeignKey(BuildingSite)
  - company: ForeignKey(Company)
  - start_date: Date
  - finish_date: Date

CompanyWorkerRelationship:
  - company: ForeignKey(Company)
  - worker: ForeignKey(Worker)
  - craft: String
  - contract: String

BuildingSiteWorkerRelationship:
  - building_site: ForeignKey(BuildingSite)
  - company: ForeignKey(Company)
  - worker: ForeignKey(Worker)
  - start_date: Date
  - finish_date: Date

Alternatively fot the third link I have thoght it can be interessant to connect both relationships, because so it is easier to follow one from another.

BuildingSiteWorkerRelationship:
  - building_site_company_relationship: ForeignKey(BuildingSiteCompanyRelationship)
  - worker: ForeignKey(Worker)
  - start_date: Date
  - finish_date: Date

Is it a good idea to model it in Django?

  • Your scheme links are excess and may produce contradictory joinings. – Akina Jul 4 at 13:45
  • Any alternative? – Antonio Romero Oca Jul 4 at 13:55
  • Analyse everything more deep. In practice it must be that two entities are related forming pairs, and third entity is related to that pair, not to separate entity. – Akina Jul 4 at 13:58
  • So do you mean, the second Example for BuildingSiteWorkerRelationship is a good approach. – Antonio Romero Oca Jul 4 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.