Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update embedded models in Loopback 4 #2011

Closed
naveenkumashi opened this issue Nov 10, 2018 · 3 comments
Closed

Update embedded models in Loopback 4 #2011

naveenkumashi opened this issue Nov 10, 2018 · 3 comments

Comments

@naveenkumashi
Copy link

Description / Steps to reproduce / Feature proposal

I have the following model relationship in my LoopBack 4 application: A Survey has 1-many relationship with Question, Question has 1-many relationship with Option.

Am using MongoDB as the database. I am unable to figure out how to implement a PUT/PATCH REST api, that can update the entire Survey model containing the Questions and Options.

Current Behavior

I get the following exception when i try a PATCH on the sample request JSON below:

Exception: Unhandled error in PATCH /5be3e00aad0df83d10e580d1: 500 TypeError: Class constructor Question cannot be invoked without 'new' at Function.DataAccessObject._coerce (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\dao.js:1799:22) at doUpdate (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\dao.js:2735:20) at C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\dao.js:2714:11 at doNotify (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:155:49) at doNotify (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:155:49) at Function.ObserverMixin._notifyBaseObservers (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:178:5) at Function.ObserverMixin.notifyObserversOf (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:153:8) at Function.ObserverMixin._notifyBaseObservers (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:176:15) at Function.ObserverMixin.notifyObserversOf (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:153:8) at C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\dao.js:2699:11 at doNotify (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:155:49) at doNotify (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:155:49) at Function.ObserverMixin._notifyBaseObservers (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:178:5) at Function.ObserverMixin.notifyObserversOf (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:153:8) at Function.ObserverMixin._notifyBaseObservers (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:176:15) at Function.ObserverMixin.notifyObserversOf (C:\Users\nk\Documents\Project\backend\surveyService\node_modules\loopback-datasource-juggler\lib\observer.js:153:8)

Sample PATCH request: [{ "title": "Some survey title 1", "description": "Some survey title 1", "questions": [{ "options": [{ "description": "Some option description 1", "type": "Option" }], "description": "Some question description 1" }] }]

Expected Behavior

It should be possible to update embedded models.

Thanks in advance.

@jedmarcnocum
Copy link

jedmarcnocum commented Dec 6, 2018

I am having the same problem. Updating embedded Model (array) throws the same error even in the example-shopping sample API.

500 TypeError: Class constructor ShoppingCartItem cannot be invoked without 'new' at Function.DataAccessObject._coerce (loopback4-example-shopping-master\loopback4-example-shopping-master\node_modules\loopback-datasource-juggler\lib\dao.js:1869:22)

@saurabhg22
Copy link

Getting same error:
Unhandled error in POST /users: 500 TypeError: Class constructor Phone cannot be invoked without 'new'
at User.set [as phone]

import { Entity, model, property } from '@loopback/repository';


@model()
class Phone {
  @property()
  number: number;

  @property()
  code: string;
}

@model()
export class User extends Entity {
  @property({
    type: 'string',
    id: true,
  })
  id: string;


  @property()
  name: string;

  @property()
  phone: Phone;

  constructor(data?: Partial<User>) {
    super(data);
  }
}

@bajtos
Copy link
Member

bajtos commented Dec 10, 2018

Closing as a duplicate of #2130

@bajtos bajtos closed this as completed Dec 10, 2018
@loopbackio loopbackio locked as resolved and limited conversation to collaborators Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants