Вопрос

I've been working on a calorie counter and I'm slowly making progress on my MQL write. The issue that I'm having currently is updating the recipe itself which is in the /common/topic/description property.

The query that I am using currently is:

[{
  id: recipeId, // previously retrieved
  '/common/topic/description': {
    connect: 'replace',
    value: $('#description textarea').val(),
    lang: '/lang/en'
  }
}]

This succeeds in executing, but when I query (another) after it has run I get an error:

{
  "domain": "global",
  "reason": "invalid",
  "message": "Unique query may have at most one result. Got 2",
  "locationType": "other",
  "location": "/common/topic/description"
}

According to the documentation, connect: replace does an update on unique properties and an insert on non-unique ones. So am I getting that because a value was inserted?

Is it necessary to remove the other value to prevent the error? Do I need to know the existing value in order to remove it?

{
  id: recipeId,
  '/common/topic/description': {
    connect: 'delete',
    value: 'Value currently stored',
    lang: '/lang/en'
  }
}
Это было полезно?

Решение

The problem doesn't anything to do with updating non-unique properties. Your read query is the issue. You didn't quote the failing query, but the part of the error message that says "location": "/common/topic/description" is your hint. That topic has two descriptions, one empty and one not, but you haven't used array notation in you query.

This will work:

[{
  "id": "/m/0wh83sg",
  "/food/recipe/ingredients": [{
    "id": null,
    "ingredient": {
      "id": null,
      "name": null,
      "/food/food/energy": null,
      "/common/topic/image": {
        "id": null,
        "optional": true,
        "limit": 1
      },
      "optional": true
    },
    "unit": {
      "id": null,
      "name": null,
      "optional": true
    },
    "quantity": null,
    "notes": null
  }],
  "/common/topic/description": [{}]
}]
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top