Home > front end >  How to make slight changes to objects related to each other without copying/creating new instances i
How to make slight changes to objects related to each other without copying/creating new instances i

Time:08-03

I have a Lessons Model, and I have a Challenges model. Right now they are related with foreign keys. So 1 lesson can have multiple challenges. My problem is that I want to re-use the Challenges objects in other lessons, but sometimes with very slight changes in the given challenge object. Up until now, I have just copied the challenge object, slightly changed it, and used that for the new lesson. The problem with this is that the database gets polluted with a bunch of similar objects, making it hard to scale with many lessons.

CodePudding user response:

If you want to associate a challenge to multiple lessons, you need to use a many-to-many relationship instead of a foreign key. If the changing fields are always the same, a through model can be used to contain them. If you change multiple fields you are probably already using the best solution.

  • Related