-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
I am having the same problem. Updating embedded Model (array) throws the same error even in the example-shopping sample API.
|
Getting same error: 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);
}
} |
Closing as a duplicate of #2130 |
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.
The text was updated successfully, but these errors were encountered: