validate method

void validate()

Implementation

void validate() {
  if (properties.isEmpty) {
    if (!lastPropertyId.isEmpty) {
      throw StateError(
          'lastPropertyId is not empty although there are no properties');
    }
  } else {
    var lastPropertyIdFound = false;
    for (final p in properties) {
      if (p.entity != this) {
        throw StateError(
            "property '${p.name}' with id ${p.id} has incorrect parent entity reference");
      }
      if (lastPropertyId.id < p.id.id) {
        throw StateError(
            "lastPropertyId $lastPropertyId is lower than the one of property '${p.name}' with id ${p.id}");
      }
      if (lastPropertyId.id == p.id.id) {
        if (lastPropertyId.uid != p.id.uid) {
          throw StateError(
              "lastPropertyId $lastPropertyId does not match property '${p.name}' with id ${p.id}");
        }
        lastPropertyIdFound = true;
      }
    }

    if (!lastPropertyIdFound &&
        !model.retiredPropertyUids.contains(lastPropertyId.uid)) {
      throw StateError(
          'lastPropertyId $lastPropertyId does not match any property');
    }
  }

  for (final r in relations) {
    if (r.targetId.isEmpty) {
      throw StateError(
          "relation '${r.name}' with id ${r.id} has incorrect target entity reference");
    }
  }
}