gpt4 book ai didi

many-to-many - Parse.com 多对多属性

转载 作者:行者123 更新时间:2023-12-01 11:38:11 25 4
gpt4 key购买 nike

“成分”和“配方”之间存在多对多关系。我知道我可以使用

从关系中添加和删除对象
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);

但这只是增加了成分。我还如何存储“数量”等字段以及添加的每种成分? (比如数据透视表上的额外属性?)

谢谢!

最佳答案

你不能。这是 Parse 的许多限制之一。您将不得不放弃内置关系模型,创建您自己的联接表。也就是说,创建一个新的对象类型,它有两个指针:第一个,源对象;第二,目标。这样就形成了关系。然后您可以在此表上添加字段以充当关系的属性。如果需要,您可以从最初持有关系的对象中保留一个指针,以连接表条目为目标。

当然,一旦您意识到这会使您使用的请求数量翻倍(每个数据库命中显然是一个“请求”),您就会开始意识到 Parse 数据库模型及其收费模型的规模大约为以及用火柴棍 build 摩天大楼。

关于many-to-many - Parse.com 多对多属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25161959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com