我正在致力于calorie counter,我可以创建新的配方,但我在尝试更新配料时遇到问题。如何使用mql更新子对象
我可以创建具有以下MQL的成分:
{
id: recipeId,
'/food/recipe/ingredients': {
create: 'unless_exists',
id: null,
quantity: parseFloat(row.$quantity.val()),
unit: {
id: row.$units.val()
},
ingredient: {
id: row.ingredientId
}
}
}
但是,如果我改变了成分的措施,从说2至3杯,这个查询将创建一个新的成分。我一直在尝试更新条目。到目前为止,我已经尝试过:
{
connect: 'update',
id: row.rowId,
type: '/food/recipe_ingredient',
quantity: parseFloat(row.$quantity.val()),
unit: {
id: row.$units.val()
},
ingredient: {
id: row.ingredientId
}
}
这会导致错误:Can't use [], [{}] or {} in a write
。
{
connect: 'update',
id: row.rowId,
type: '/food/recipe_ingredient',
quantity: parseFloat(row.$quantity.val())
}
结果的错误:Can't use 'connect' at the root of the query
。
{
id: recipeId,
'/food/recipe/ingredients': {
connect: 'update',
id: row.rowId,
type: '/food/recipe_ingredient',
quantity: parseFloat(row.$quantity.val())
}
}
我得到的错误:Can't use 'connect': 'update' on a non-unique master property
。
{
id: row.rowId,
type: '/food/recipe_ingredient',
quantity: {
connect: 'update',
value: parseFloat(row.$quantity.val())
}
}
导致错误:This value is already in use. Please delete it first.
是删除旧的成分,并添加一个新的唯一途径?
如果唯一的方法是删除旧的条目,并替代它们,有没有什么办法,在与像查询删除所有成分一次,而不是单独:
{
id: recipeId,
'/food/recipe/ingredients': {
connect: 'delete',
id: row.rowId
}
}
您使用哪种语言? parseFloat()和$ quantity不是MQL表达式。我猜你试图操纵CVT而不理解它们如何连接。 –
我在javascript中构建查询,并将这些条目解引用值。它们不会传递到写入端点。 – Will