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
## Refactor:
* refactor(query-builder): move query attributes into its own object
* This slightly reduces size and looks better when logging a model out
* refactor(model)!: remove non-static `find` method
* If the model is instantiated it is likely to have been hydrated with data.
If it has then, nothing to find. If it hasn't then the static method is enough.
* refactor(internal): moved existence check up the class chain
* refactor(model)!: remove `findMany` non-static method
* refactor(model)!: removed `when` and `unless` non-static methods
* refactor(model): move 'when` and `unless` methods to the model
* refactor(internal): rename withouts query parameter to without
## Feature:
* feat(helpers): added `value` function
* feat(api-calls): add `setModelEndpoint` helper method
* feat(model): added `tap` method
* feat(model): added function resolving to `when` and `unless` methods
## Fix:
* fix(relations): added existence check for `load` method
* fix(api-calls): improved `get` method's type argument/return
* fix(relations): fix `morphTo` relation
* Endpoint was not set correctly for the next request
* fix(model): add missing lastSyncedAt copy in the `clone` method
## Chore:
* chore: increment version
* chore: add optional peer dependencies
* chore(deps-dev): updated dependencies
## Documentation
* docs(model): fix heading for `make` section
* docs(helpers): documented `value` function
* docs(timestamps): removed invalid todo comment
## Testing
* test(model): improved `tap`'s test
* test(relations): fix morphTo test
The `setLastSyncedAt` method sets the [_lastSyncedAt](#_lastsyncedat) attribute to the current [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date). It optionally also accepts an argument for the value to be set as. The set value is subject to the [date-time casting](./attributes.md#datetime).
155
+
The `setLastSyncedAt` method sets the [_lastSyncedAt](#_lastsyncedat) attribute to the current [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date). It optionally also accepts an argument for the value to be set as. The set value is subject to the [date-time casting](./attributes.md#datetime). Furthermore, it takes timestamps into consideration when enabled.
156
156
157
157
::: warning
158
158
This method should only really be used when mocking the model to look like it exists. Some possible use-cases are:
Copy file name to clipboardExpand all lines: docs/calliope/query-building.md
-20Lines changed: 0 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -241,26 +241,6 @@ import User from '@Models/User';
241
241
User.limit(5);
242
242
```
243
243
244
-
#### when
245
-
246
-
The `when` method calls the given closure when the first argument evaluates to a truthy value, allowing for adding constraints conditionally without breaking the method chaining.
247
-
248
-
```js
249
-
importUserfrom'@Models/User';
250
-
251
-
User.when(() =>true, model=>model.whereKey(1));
252
-
```
253
-
254
-
#### unless
255
-
256
-
The `unless` method calls the given closure when the first argument evaluates to a falsy value, allowing for adding constraints conditionally without breaking the method chaining.
The `create` method instantiates your model while setting up attributes and relations. This will mass assign attributes to the model while respecting the [guarding](./attributes#guarding) settings.
173
+
The `make` method instantiates your model while setting up attributes and relations. This will mass assign attributes to the model while respecting the [guarding](./attributes#guarding) settings.
174
174
175
175
```ts
176
176
importUserfrom'@Models/User';
@@ -218,7 +218,7 @@ The `clone` method clones the instance in its current state. Meaning all changes
The `tap` method allows to use the model without affecting the model it is called on.
232
+
233
+
```js
234
+
importUserfrom'@Models/User';
235
+
236
+
constuser=User.factory().createOne();
237
+
user.with('relation')
238
+
.select(['attribute1', 'attribute2'])
239
+
.tap(console.log) // the model logged out to the console
240
+
.tap(model=>model.with('another-relation')) // will NOT add `another-relation` to the next query
241
+
.get();
242
+
```
243
+
244
+
#### when
245
+
246
+
The `when` method calls the given closure when the first argument evaluates to a truthy value, allowing for changing the model conditionally without breaking the method chaining.
247
+
248
+
```js
249
+
importUserfrom'@Models/User';
250
+
251
+
User.make()
252
+
.when(true, user=>user.setAttribute('test', 1))
253
+
.when(() =>false, user.setAttribute('test', 2))
254
+
.getAttribute('test'); // 1
255
+
```
256
+
257
+
#### unless
258
+
259
+
The `unless` method calls the given closure when the first argument evaluates to a falsy value, allowing for changing the model conditionally without breaking the method chaining.
The `value` is a function that simply resolves the given argument. If function given it will call the function with the passed in parameters. If not function given, it will return the value.
0 commit comments