0

I have two loop back models like this:

{
  "name": "se_unvrs_fields_cat",
  "base": "PersistedModel",
  "options": {
    "validateUpsert": true
  },
  "mysql": {
    "schema": "segtool",
    "table": "se_unvrs_fields_cat"
  },
  "properties": {
    "cat_id": {
      "type": "Number",
      "id": true,
      "required": true
    },
    "cat_nm": {
      "type": "string",
      "required": false
    },
    "insrt_dt": {
      "type": "Date",
      "required": false
    },
    "insrt_user_id": {
      "type": "String",
      "required": false
    },
    "upd_dt": {
      "type": "Date",
      "required": false
    },
    "upd_user_id": {
      "type": "String",
      "required": false
    }
  },
  "validations": [],
  "relations": {
    "seUnvrsFields": {
      "type": "hasMany",
      "model": "se_unvrs_fields",
      "foreignKey": "cat_id"
    }
  },
  "acls": [],
  "methods": []
}

and another:

{
  "name": "se_unvrs_fields",
  "base": "PersistedModel",
  "options": {
    "validateUpsert": true
  },
  "mysql": {
    "schema": "segtool",
    "table": "se_unvrs_fields"
  },
  "properties": {
    "unvrs_field_nm": {
      "type": "String",
      "required": false,
      "id": true
    },
    "cat_id": {
      "type": "Number",
      "required": true,
      "index": true
    },
    "insrt_dt": {
      "type": "Date",
      "required": false
    },
    "insrt_user_id": {
      "type": "String",
      "required": false
    },
    "upd_dt": {
      "type": "Date",
      "required": false
    },
    "upd_user_id": {
      "type": "String",
      "required": false
    }
  },
  "validations": [],
  "relations": {
    "seUnvrsFieldsCat": {
      "type": "belongsTo",
      "model": "se_unvrs_fields_cat",
      "foreignKey": "cat_id"
    }
  },
  "acls": [],
  "methods": []
}

when I query the the seSegnUnvrsFields model as such in REST api:

{"include": "seUnvrsFieldsCat"}

I get this error in the CMD:

c:\BMO\segtool\node_modules\loopback-connector-mysql\node_modules\mysql\lib\protocol\Parser.js:82
    throw err;
          ^
Error: Invalid date: Invalid Date
    at DateType (c:\BMO\segtool\node_modules\loopback-datasource-juggler\lib\model-builder.js:521:11)
    at ModelConstructor.Object.defineProperty.set [as insrt_dt] (c:\BMO\segtool\node_modules\loopback-datasource-juggler\lib\model-builder.js:456:81)
    at ModelConstructor.ModelBaseClass._initProperties (c:\BMO\segtool\node_modules\loopback-datasource-juggler\lib\model.js:177:17)
    at ModelConstructor.ModelBaseClass (c:\BMO\segtool\node_modules\loopback-datasource-juggler\lib\model.js:46:8)
    at ModelConstructor (c:\BMO\segtool\node_modules\loopback-datasource-juggler\lib\model-builder.js:177:22)
    at ModelConstructor (c:\BMO\segtool\node_modules\loopback-datasource-juggler\lib\model-builder.js:177:22)
    at new ModelConstructor (c:\BMO\segtool\node_modules\loopback-datasource-juggler\lib\model-builder.js:177:22)
    at c:\BMO\segtool\node_modules\loopback-datasource-juggler\lib\include.js:172:48
    at c:\BMO\segtool\node_modules\loopback-datasource-juggler\node_modules\async\lib\async.js:125:13
    at Array.forEach (native)

its says its a datetime error but I use the same date time in other models and it works fine. Whats also weird is that if I query

{"include": "seUnvrsFields"}

from seUnvrsFieldsCat, that works, but not the other way....

lightweight
  • 3,227
  • 14
  • 79
  • 142
  • Do you know what version of Node and Loopback you are using? – JSimonsen Aug 05 '15 at 17:42
  • Node version is v0.12.7 and here is my dependencies list: `"dependencies": { "compression": "^1.0.3", "cors": "^2.5.2", "errorhandler": "^1.1.1", "loopback": "^2.14.0", "loopback-boot": "^2.6.5", "loopback-connector-mysql": "^1.7.0", "loopback-datasource-juggler": "^2.19.0", "serve-favicon": "^2.0.1" },` – lightweight Aug 05 '15 at 18:08
  • Do you know if any of your post data contains a Null value for date? – JSimonsen Aug 05 '15 at 18:58
  • nope, they all have dates. On a note on that, some of the other models do have null dates but they work fine. – lightweight Aug 07 '15 at 15:22
  • 1
    The only comment I will make, at least to me, the following: Error: Invalid date: Invalid Date Would indicate that a date field is actually set to 'Invalid Date' or the property is getting to set to that during processing since its 'null' and your schema 'seUnvrsFieldsCat' belongsTo the other model. So I would suspect that the nulls may be causing the problem due to the belongsTo processing....but not sure... – doktoroblivion Aug 08 '15 at 20:46
  • I agree with what @ErickGriffin said. Also, semi related... if you try `var day = new Date('null');`. The value of `day` is equal to `Invalid Date`. – dannypaz Aug 10 '15 at 06:58

0 Answers0