I'm working on a calorie counter and I can create new recipes, but I am having problems trying to update an ingredient.
I can create an ingredient with the following 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
}
}
}
However if I change an ingredient's measure, say from 2 to 3 cups, this query will create a new ingredient. I've been trying to update the entry. So far I've tried:
{
connect: 'update',
id: row.rowId,
type: '/food/recipe_ingredient',
quantity: parseFloat( row.$quantity.val() ),
unit: {
id: row.$units.val()
},
ingredient: {
id: row.ingredientId
}
}
This results in the error: Can't use [], [{}] or {} in a write
.
{
connect: 'update',
id: row.rowId,
type: '/food/recipe_ingredient',
quantity: parseFloat( row.$quantity.val() )
}
Results in the error: 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() )
}
}
I get the error: 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() )
}
}
Results in the error: This value is already in use. Please delete it first.
Is the only way to delete the old ingredient and add a new one?
If the only way is to delete the old entries and replace them, is there any way to remove all the ingredients at once rather than individually with queries like:
{
id: recipeId,
'/food/recipe/ingredients': {
connect: 'delete',
id: row.rowId
}
}