I'm having difficulty reproducing this error. I'm ...
# community-help
h
I'm having difficulty reproducing this error. I'm trying with this schema
Copy code
{
  "name": "Foods",
  "fields": [
    {
      "name": "name",
      "type": "string"
    },
    {
      "name": "portions",
      "type": "object[]"
    },
    {
      "name": "portions.portion_id",
      "type": "string[]",
      "reference": "Portions.portion_id",
      "optional": true
    }
  ],
  "enable_nested_fields": true
}
{
  "name": "Portions",
  "fields": [
    {
      "name": "portion_id",
      "type": "string"
    },
    {
      "name": "quantity",
      "type": "int32"
    },
    {
      "name": "unit",
      "type": "string"
    }
  ]
}
Indexed these documents:
Copy code
{
  "portion_id": "portion_a",
  "quantity": 500,
  "unit": "g"
}
{
  "portion_id": "portion_b",
  "quantity": 1,
  "unit": "lt"
}
{
  "portion_id": "portion_c",
  "quantity": 500,
  "unit": "ml"
}
and this food:
Copy code
{
  "name": "Milk",
  "portions": [
    {
      "portion_id": "portion_b",
      "count": 3
    },
    {
      "count": 3
    },
    {
      "portion_id": "portion_c",
      "count": 1
    }
  ]
}
For
Copy code
{"collection", "Foods"},
{"q", "*"},
{"include_fields", "$Portions(*:merge)"}
I receive
Copy code
{
  "name": "Milk",
  "portions": [
    {
      "count": 3,
      "id": "1",
      "portion_id": "portion_b",
      "quantity": 1,
      "unit": "lt"
    },
    {
      "count": 3
    },
    {
      "count": 1,
      "id": "2",
      "portion_id": "portion_c",
      "quantity": 500,
      "unit": "ml"
    }
  ]
}
with
:merge
.