You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module is designed for the [Strongloop Loopback](https://github.com/strongloop/loopback) framework. It automatically adds `createdAt`and `updatedAt` attributes to any Model.
4
+
This module is designed for the [Strongloop Loopback](https://github.com/strongloop/loopback) framework. It automatically adds `createdAt`, `updatedAt`and `deletedAt` attributes to any Model.
12
5
13
6
`createdAt` will be set to the current Date the by using the default property of the attribute.
14
7
15
8
`updatedAt` will be set for every update of an object through bulk `updateAll` or instance `model.save` methods.
16
9
10
+
`deletedAt` will be set for every delete of an object through bulk `deleteAll` or instance `model.delete` methods.
11
+
17
12
This module is implemented with the `before save`[Operation Hook](http://docs.strongloop.com/display/public/LB/Operation+hooks#Operationhooks-beforesave) which requires the loopback-datasource-juggler module greater than [v2.23.0](strongloop/loopback-datasource-juggler@0002aaedeffadda34ae03752d03d0805ab661665).
18
13
19
14
INSTALL
@@ -23,11 +18,6 @@ INSTALL
23
18
npm i loopback-ds-timestamp-mixin --save
24
19
```
25
20
26
-
UPSERT ISSUES
27
-
=============
28
-
29
-
With version 2.33.2 of this module the [upsert validation was turned off](https://github.com/clarkbw/loopback-ds-timestamp-mixin/blob/master/es6/time-stamp.js#L16). This may create issues for your project if upsert validation is required. If you require upsert validation, set the `validateUpsert` option to true, however most upserts will fail unless you supply the `createdAt` and `updatedAt` fields or set `required` option to false.
30
-
31
21
SERVER CONFIG
32
22
=============
33
23
@@ -44,7 +34,7 @@ Add the `mixins` property to your `server/model-config.json`:
44
34
],
45
35
"mixins": [
46
36
"loopback/common/mixins",
47
-
"../node_modules/loopback-ds-timestamp-mixin",
37
+
"../node_modules/loopback-timestamp-mixin",
48
38
"../common/mixins"
49
39
]
50
40
}
@@ -73,16 +63,12 @@ To use with your Models add the `mixins` attribute to the definition object of y
73
63
MODEL OPTIONS
74
64
=============
75
65
76
-
The attribute names `createdAt`and `updatedAt` are configurable. To use different values for the default attribute names add the following parameters to the mixin options.
66
+
The attribute names `createdAt`, `updatedAt`and `deletedAt` are configurable. To use different values for the default attribute names add the following parameters to the mixin options.
77
67
78
-
You can also configure whether `createdAt` and `updatedAt` are required or not. This can be useful when applying this mixin to existing data where the `required` constraint would fail by default.
79
-
80
-
By setting the `validateUpsert` option to true you will prevent this mixin from overriding the default Model settings. With validation turned on most upsert operations will fail with validation errors about missing the required fields like `createdAt` or `updatedAt`.
68
+
You can also configure whether `createdAt`, `updatedAt` and `deletedAt` are required or not. This can be useful when applying this mixin to existing data where the `required` constraint would fail by default.
81
69
82
70
This mixin uses console logs to warn you whenever something might need your attention. If you would prefer not to receive these warnings, you can disable them by setting the option `silenceWarnings` to `true` on a per model basis.
83
71
84
-
In this example we change `createdAt` and `updatedAt` to `createdOn` and `updatedOn`, respectively. We also change the default `required` to `false` and set `validateUpsert` to true. We also disable console warnings with `silenceWarnings`.
85
-
86
72
```json
87
73
{
88
74
"name": "Widget",
@@ -93,10 +79,9 @@ In this example we change `createdAt` and `updatedAt` to `createdOn` and `update
0 commit comments