Parse.com many-to-many with attributes

I have a many-to-many relationship between Ingredient and Recipe. I know that I can add and remove an object from a relationship using

var Recipe = Parse.Object.extend("Recipe");
var Ingredient = Parse.Object.extend("Ingredient");

var recipe = new Recipe();
var ingredient = new Ingredient();

ingredient.id = "abcDef1234"; //random

var recipe_ingredients = recipe.relation("recipe_ingredients");
recipe_ingredients.add(ingredient);

      

But that only adds an ingredient. How do you store a field like "quantity" along with each added ingredient? (How are additional attributes on a pivot table?)

Thank!

+3


source to share


1 answer


You can not. This is one of the limitations of Parse many . You will have to abandon the inline relationship model and create your own join table. That is, create a new type of object that has two pointers: the first, the original object; the second is the goal. It creates an attitude. Then you can add fields to this table to act like relationship attributes. If you want, you can keep a pointer from the entity that originally associated this relationship, targeting a join table entry.



Of course, once you realize that this doubles the number of queries you are using (presumably every database query is a "query"), then you begin to realize that Parse's database model combined with their charging model scales roughly so: as well as the construction of skyscrapers from matches.

+5


source







All Articles