mardi 5 mai 2015

How to model many to many relationships without circles

Let's say I have two table, Recipe and Ingredient, how can I model these two tables in code when there is a many to many relationship between them. My approach was to create two classes, Recipe and Ingredient. Recipe has a list with every ingredient used in that recipe, and Ingredient has a list with every Recipe it's used in. The problem is that Ingredient holds a list of Recipe which holds a list of Ingredient which holds a list of Ingredient, and so on, like two mirrors facing each other. How can I avoid this behavior.

Aucun commentaire:

Enregistrer un commentaire