Loopback model CURRENT_TIMESTAMP

Jahid Shohel picture Jahid Shohel · Jan 23, 2015 · Viewed 10.6k times · Source

I have a model like this -

{
  "name": "MakeCallTestConfiguration",
  "base": "PersistedModel",
  "idInjection": true,
  "properties": {
    "id": {
      "type": "number",
      "id": true,
      "generated": true
    },
    "destination": {
      "type": "string",
      "required": true
    },
    "clientId": {
      "type": "number",
      "required": true
    },
    "logTime":{
      "type" : "date",
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": []
}

For "logTime", how can I have auto generated time stamp? I mean something like

"TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"

Answer

Emmanuel P. picture Emmanuel P. · Jun 3, 2016

You can use the "$now" attribute

"logTime":{
  "type": "date",
  "required": true,
  "default": "$now"
}