differIn method

Iterable<FieldWithValue> differIn(
  1. DbModel other, {
  2. List<FieldWithValue>? fieldsToCheck,
  3. bool? allFields = true,
})

Get the fields that has different values.

other The other model want to copy values from.

allFields Check (id, serverId, creationTime, modificationTime) values.

Implementation

Iterable<FieldWithValue> differIn(DbModel other,
    {List<FieldWithValue>? fieldsToCheck, bool? allFields = true}) sync* {
  assert(allFields != null);
  // assert(runtimeType == other.runtimeType);

  Map<String?, FieldWithValue> fieldsMap = {};
  for (var e
      in (allFields! ? getAllFields() : fieldsToCheck ?? getFields()!)) {
    fieldsMap[e!.columnName] = e;
  }

  Map<String, FieldWithValue> otherFieldsMap = {};
  for (var e in (allFields
      ? other.getAllFields()
      : fieldsToCheck == null
          ? other.getFields()!
          : other._getNamedFields(
              fieldsToCheck.map((e) => e.columnName).toList()))) {
    otherFieldsMap[e!.columnName!] = e;
  }

//compare values
  for (var k in fieldsMap.keys) {
    var thisValue = fieldsMap[k]!.value;
    var otherValue = otherFieldsMap[k]!.value;

    if (thisValue != otherValue) {
      yield fieldsMap[k]!;
    }
  }
}