loopback-ds-timestamp-mixin
loopback-ds-timestamp-mixin copied to clipboard
Issue - Embedded Data Models failing to POST
Hi,
Been using your plugin lately. Faced some issues when I tried to POST a Model that has Embedded Models inside it.
{
"error": {
"name": "ValidationError",
"status": 422,
"message": "The `Option` instance is not valid. Details: `content` is invalid: `updatedAt` can't be blank (value: undefined).",
"statusCode": 422,
"details": {
"context": "Option",
"codes": {
"content": [
"invalid"
]
},
"messages": {
"content": [
"is invalid: `updatedAt` can't be blank"
]
}
},
"stack": "ValidationError: The `Option` instance is not valid. Details: `content` is invalid: `updatedAt` can't be blank (value: undefined).\n at P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-datasource-juggler\\lib\\dao.js:264:12\n at ModelConstructor.<anonymous> (P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-datasource-juggler\\lib\\validations.js:472:11)\n at ModelConstructor.next (P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-datasource-juggler\\lib\\hooks.js:75:12)\n at ModelConstructor.<anonymous> (P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-datasource-juggler\\lib\\validations.js:469:23)\n at ModelConstructor.trigger (P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-datasource-juggler\\lib\\hooks.js:65:12)\n at ModelConstructor.Validatable.isValid (P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-datasource-juggler\\lib\\validations.js:435:8)\n at P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-datasource-juggler\\lib\\dao.js:260:9\n at P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-datasource-juggler\\lib\\observer.js:106:23\n at P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-datasource-juggler\\node_modules\\async\\lib\\async.js:189:25\n at event (P:\\testproject\\server_workbench\\testproject\\node_modules\\loopback-ds-timestamp-mixin\\index.js:29:5)"
}
}
Model Info
Option {
id (number, optional),
optionContent (Content, optional),
createdAt (string),
updatedAt (string)
}
Content {
data (string),
type (string),
id (number, optional),
createdAt (string),
updatedAt (string)
}
Model's JSON in Loopback:
{
"name": "Option",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
},
"validations": [],
"relations": {
"content": {
"type": "embedsOne",
"model": "Content",
"property": "optionContent",
"options": {
"validate": true,
"forceId": true,
"persistent": true
}
}
},
"mixins": {
"TimeStamp": true
},
"acls": [],
"methods": []
}
{
"name": "Content",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"data": {
"type": "string",
"required": true
},
"type": {
"type": "string",
"required": true
}
},
"mixins": {
"TimeStamp": true
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
Here is what I Inserted:
{
"optionContent": {
"data": "asdasd",
"type": "text"
}
}
The Bug gets Fixed If I remove Timestamp from the inner Model "Content"
@vasumahesh1 thanks for the detailed information! what version are you running?
Also if you could try running your server with the debug information turned on during your POST to see if there's any other interesting output happening.
Something like this DEBUG='loopback-ds-timestamp-mixin' slc run
Version:
{
"name": "testproject",
"version": "1.0.0",
"main": "server/server.js",
"scripts": {
"pretest": "jshint ."
},
"dependencies": {
"compression": "^1.0.3",
"cors": "^2.5.2",
"errorhandler": "^1.1.1",
"loopback": "^2.14.0",
"loopback-boot": "^2.6.5",
"loopback-datasource-juggler": "^2.19.0",
"loopback-ds-timestamp-mixin": "^2.1.1",
"serve-favicon": "^2.0.1"
},
"optionalDependencies": {
"loopback-explorer": "^1.1.0"
},
"devDependencies": {
"jshint": "^2.5.6"
},
"repository": {
"type": "",
"url": ""
},
"description": "test project"
}
Okay i'll try to run in Debug mode ...
It looks like its failing validation on the embeded object, I'll have to look into why this is happening.
For now you could set required
to false
for your Content
model with something like this:
"mixins": {
"TimeStamp" : {
"required" : false
}
}