Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Issue - Embedded Data Models failing to POST #12

Open
vasumahesh1 opened this issue Jun 24, 2015 · 5 comments
Open

Issue - Embedded Data Models failing to POST #12

vasumahesh1 opened this issue Jun 24, 2015 · 5 comments

Comments

@vasumahesh1
Copy link

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"
  }
}
@vasumahesh1
Copy link
Author

The Bug gets Fixed If I remove Timestamp from the inner Model "Content"

@clarkbw
Copy link
Owner

clarkbw commented Jun 24, 2015

@vasumahesh1 thanks for the detailed information! what version are you running?

@clarkbw
Copy link
Owner

clarkbw commented Jun 24, 2015

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

@vasumahesh1
Copy link
Author

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 ...

@clarkbw
Copy link
Owner

clarkbw commented Jun 24, 2015

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
  }
}

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

2 participants