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
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 `create` method instantiates your model while setting up attributes and relations.
174
174
175
175
```ts
176
176
importUserfrom'@Models/User';
@@ -181,18 +181,6 @@ const user = User.create({ name: 'User Name' }); // User
181
181
Constructing a new class like `new User({...})` is **not** acceptable. This will not overwrite your class fields with default values if the same key has been passed in due to how JavaScript first constructs the parent class and only then the subclasses. However, you can still use it to call instance methods. Furthermore, it will not cause unexpected results if using it with the [setAttribute](./attributes.md#setattribute) method or call methods that under the hood uses the [setAttribute](./attributes.md#setattribute).
182
182
:::
183
183
184
-
::: tip
185
-
When creating an instance and passing in another instance of the model:
186
-
```js
187
-
importUserfrom'@Models/User';
188
-
importShiftfrom'@Models/Shift';
189
-
190
-
constuser=User.create({ name:'John Doe' });
191
-
constnewUser=User.create(user);
192
-
```
193
-
It will clone the [raw attributes](./attributes#getrawattributes) and the [relationships](./relationships.md#getrelations) of the model.
194
-
:::
195
-
196
184
#### replicate
197
185
198
186
The `replicate` method copies the instance into a non-existent instance. Meaning primary key and the timestamps won't be copied.
0 commit comments