I want to estabish a relation 1:N betwen two classes. I have created a domain to do so, but I’m lacking of an option that automatically relates the elements of one class with the other.
I will put an example to explain what I intend to do and the problem I have.
I have a class with recipes, and each recipe has a variable amount of ingredients. As the amount of elements cannot be changed dynamically I create another class to store the ingredients used by the recipes. My idea is to reference them by a common id, what I mean by this is that I will create an attribute in the ingredient class that stores the ID of the recipe that contains it. The problem I have at this point is that when I define the domain to relate the two classes in a 1:N relationship there is no option to set the relationship as I want. The only way I have found to achieve this is to set the references manually which is not sustainable for large amounts of data.
I would like to know if there is any other way to make these references automatically so that I can solve my problem.
So you try to link ingredients to a recipes? Do you store ingredients in one class and recipes in another? If the answer to both questions is “Yes” - I suppose each ingredient can be used in more than one recipe and each recipe can use more than one ingredient. If so - you can not use 1:N relation, but should be using N:N. I’m not sure about your specific use case, but if I were trying to build a cook-book using CMDBuild I would create N:N relation between ingredient and a recipe and will add an relation attribute to indicate an amount of ingredient for a specific recipe. Then I would use something like a report to generate full recipe with cooking instructions from recipe card and list of ingredients (and their amounts) from this relations/domain. It indeed can be inconvenient to link each ingredient one-by-one to a recipe card, so I would create a process (look at the Asset Management from Ready2Use) to link everything easily.