setAttributes method
Convenience method to fill attributes from a map, respecting fillable/guarded rules.
This is a wrapper around fillAttributes that makes the API more intuitive.
Only attributes marked as fillable (or not guarded) will be set.
Example:
final user = await Users.query().where('id', 1).first();
user.fill({
'name': 'New Name',
'email': 'new@example.com',
});
Note: This only works properly on ORM-managed model instances. Convenience method to set multiple attributes at once without guards.
Unlike fill and forceFill, this directly sets attributes without going through the fillable/guarded logic. It's the most permissive way to bulk-set attributes.
Example:
final user = await Users.query().where('id', 1).first();
user.setAttributes({
'name': 'New Name',
'email': 'new@example.com',
'active': true,
});
Note: This only works properly on ORM-managed model instances.
Implementation
// NOTE: fill() and forceFill() methods have been moved to the Model class
// to avoid return type conflicts. The Model class methods return Model<TModel>
// for method chaining, while calling this mixin's fillAttributes() internally.
/// Convenience method to set multiple attributes at once without guards.
///
/// Unlike [fill] and [forceFill], this directly sets attributes without
/// going through the fillable/guarded logic. It's the most permissive way
/// to bulk-set attributes.
///
/// Example:
/// ```dart
/// final user = await Users.query().where('id', 1).first();
/// user.setAttributes({
/// 'name': 'New Name',
/// 'email': 'new@example.com',
/// 'active': true,
/// });
/// ```
///
/// Note: This only works properly on ORM-managed model instances.
void setAttributes(Map<String, Object?> attributes) {
for (final entry in attributes.entries) {
setAttribute(entry.key, entry.value);
}
}