Assign Properties
Enhances models with data assignment capabilities for building modifiable model instances
The withAssignProperties
mixin (also exported as withAssign
) adds data assignment capabilities to your models. This allows you to create model instances with attached data and update them in a immutable way.
Usage
API Reference
withAssignProperties()
Enhances a model with the assign
method.
ModelWithAssign
assign()
Creates a new model instance with the assigned data. This method:
- Creates a copy of the current instance
- Merges the new data into the copy
- Returns the new instance without modifying the original
Combining with Other Mixins
The assign mixin works well with other mixins to create rich model instances:
Best Practices
- Always create a new instance with
assign
rather than modifying the original - When updating the database, extract only the fields you want to update
- Combine with other mixins like
withGlobalId
orwithSlug
for richer models - Consider using TypeScript to ensure type safety for model instances