Loopback: Single attributes updates, replacing or empty values for other attributes

Created on 1 Mar 2017  路  6Comments  路  Source: strongloop/loopback

When trying to call PUT call with one or two attributes, which replacing other attributes values as empty. If anyone know please help.

stale

Most helpful comment

I have the same issue.....
Some News?

All 6 comments

i did not fully understand what you meant but normally
http://localhost:3000/api/modelName/58ad5c0490ac1a2865257f4a

with data

{
  "attribute": 'data'
}

will update the single attribute

Hi,

Data for POST call is:

-X POST 'http://localhost:3000/api/brands'

{ title: 'testing 333', status: 'active', description: 'string', brand_id: 493, slug: 'testing-333' }

Data for PUT call is:

-X PUT 'http://localhost:3000/api/brands/493'

{ title: 'testing 444', slug: 'testing-444' }

after updating remaining existing fields like "description", "status" is removed from DB. Can you please help me updating only some specific fields without deleting others. I am using Mongo DB and tried with My SQL. Same response I am getting.

Thanks in advance.

Regards,

I have the same issue.....
Some News?

Use PATCH instead of PUT

Use PATCH instead of PUT

Doesn't work. Could you please share your code?

This is from an actual working app that is using apisauce, that updates just 2 properties of the model driver.

import apisauce from 'apisauce'

const api = apisauce.create({
    // base URL is read from the "constructor"
    baseURL,
    // here are some default headers
    headers: {
      'Cache-Control': 'no-cache'
    },
    // 10 second timeout...
    timeout: 10000
  })
const updateOneSignal = (userId, oneSignalUserId, oneSignalPushToken) => 
    api.patch(`/drivers/${userId}`, { oneSignalUserId, oneSignalPushToken })

This is the model

//driver.json
{
  "name": "Driver",
  "plural": "drivers",
  "base": "User",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "plate": {
      "type": "string",
      "required": true
    },
    "firstName": {
      "type": "string",
      "required": true
    },
    "lastName": {
      "type": "string",
      "required": true
    },
    "phone": {
      "type": "number"
    },
    "oneSignalUserId": {
      "type": "string"
    },
    "oneSignalPushToken": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

dependencies:

  "dependencies": {
    "compression": "^1.0.3",
    "cors": "^2.5.2",
    "helmet": "^3.10.0",
    "loopback": "^3.22.0",
    "loopback-boot": "^2.6.5",
    "loopback-component-explorer": "^6.2.0",
    "loopback-connector-mongodb": "^3.9.2",
    "serve-favicon": "^2.0.1",
    "strong-error-handler": "^3.0.0"
  },
Was this page helpful?
0 / 5 - 0 ratings