I'm trying to set up a relationship like this:
I am making a list of all recipes across multiple recipe books. A recipe can only belong to one recipe book. A recipe has a list of components, which can either be an individual ingredient or another recipe.
So, for example, I have the recipe for a salad which has as its components lettuce (an ingredient), tomatoes (an ingredient), and dressing (a recipe). The dressing then has a list of it's own ingredients.
I want to utilize a polymorphic relationship called "Components" on the Recipe class that will self-reference the Recipe class or reference the Ingredients class.
For a recipe, I also want to be able to see if it's used in any other recipes and what the total ingredients are (i.e. it's direct ingredients and all the ingredients of its component recipes)
Can someone tell me how to set this up? I know how to do one or the other, but not both.
Thanks!