-1

when i use relation referencesMAny with array in loopback. i have got error when i remove referencesMAny relation it's working. i am using loopback 3

{ "error": { "statusCode": 500, "name": "Error", "message": "5d53eaa49b826748f0b72ca5is not an ObjectID string", }}

it's my json schema :

{
  "name": "Products",
  "plural": "Products",
  "strict": true,
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "mixins": {
    "TimeStamp": true
  },
  "properties": {
    "name": {
      "type": "string",
      "default": ""
    },
    "image": {
      "type": [],
      "required": true,
      "default": []
    },
    "about": {
      "type": "string",
      "required": true,
      "default": ""
    },
    "categoryId": {
      "type": [],
      "required": false,
      "default": []
    },
    "userId": {
      "type": "string",
      "required": true,
      "default": ""
    },
    "storeId": {
      "type": "string",
      "required": true,
      "default": ""
    },
    "location": {
      "type": "geopoint",
      "required": false
    },
    "price": {
      "type": "object",
      "required": true,
      "default": {
        "discount": "",
        "actualRate": "",
        "finalRate": ""
      }
    },
    "createdAt": {
      "type": "date"
    },
    "updatedAt": {
      "type": "date"
    }
  },
  "validations": [],
  "relations": {
    "userDeatils": {
      "type": "belongsTo",
      "model": "Users",
      "foreignKey": "userId"
    },
    "categories": {
      "type": "referencesMany",
      "model": "Categories",
      "foreignKey": "categoryId"
    },
    "storeDeatils": {
      "type": "belongsTo",
      "model": "Users",
      "foreignKey": "userId"
    }
  },
  "acls": [
    {
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "admin",
      "permission": "ALLOW"
    },
    {
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$authenticated",
      "permission": "ALLOW"
    },
    {
      "accessType": "WRITE",
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW"
    },
    {
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$unauthenticated",
      "permission": "DENY"
    }
  ],
  "methods": {}
}

my json data object like this :

{
  "name": "deara",
  "image": ["dsadsa"],
  "about": "dear ser",
  "categoryId": [
    "5d53eaa49b826748f0b72ca5"
  ],
  "userId": "dsdsadsa",
  "storeId": "dsdsadsadsad",
  "location": {
    "lat": 0,
    "lng": 0
  },
  "price": {
    "discount": "121",
    "actualRate": "321",
    "finalRate": "231"
  },
  "createdAt": "2019-08-09T12:02:54.514Z",
  "updatedAt": "2019-08-09T12:02:54.514Z"
}

i don't understand where am i wrong. thanks in advance

imran ali
  • 383
  • 1
  • 13

1 Answers1

0

Loopback expects that dsadsad232323 will be an identifier of an object of another model, so categoryId must be array of id.

Sagar Chilukuri
  • 1,430
  • 2
  • 17
  • 29
Denis Kulygin
  • 323
  • 1
  • 9