getDirty method

Map<String, Object?> getDirty()
inherited

Gets only the attributes that have been modified.

Returns a map containing only the changed attributes with their new values. Returns an empty map if nothing has changed or no original state is tracked.

Example:

final user = await Users.query().where('id', 1).first();
user.setAttribute('name', 'New Name');
user.setAttribute('email', 'new@example.com');
print(user.getDirty()); // {'name': 'New Name', 'email': 'new@example.com'}

Implementation

Map<String, Object?> getDirty() {
  final original = _getOriginalAttributes();
  if (original == null) {
    return const {};
  }

  final current = _ensureAttributes();
  final dirty = <String, Object?>{};

  for (final entry in current.entries) {
    if (original[entry.key] != entry.value) {
      dirty[entry.key] = entry.value;
    }
  }

  return dirty;
}