EntityRelation constructor

EntityRelation({
  1. required List<String> localPropNames,
  2. List<EntityJunction> junctions = const [],
  3. String? foreignTableName,
  4. required List<String> foreignPropNames,
})

Implementation

EntityRelation({
  required this.localPropNames,
  this.junctions = const [],
  this.foreignTableName,
  required this.foreignPropNames,
}) {
  if (junctions.isEmpty) {
    if (localPropNames.length != foreignPropNames.length) {
      throw ArgumentError(
          'Database keys have inconsistent number of columns.');
    }
  } else {
    if (localPropNames.length != junctions.first.localPropNames.length) {
      throw ArgumentError(
          'Database keys have inconsistent number of columns.');
    }
    var previousAssociation = junctions.first;
    for (var association in junctions.skip(1)) {
      if (association.localPropNames.length !=
          previousAssociation.foreignPropNames.length) {
        throw ArgumentError(
            'Database keys have inconsistent number of columns.');
      }
      previousAssociation = association;
    }
    if (foreignPropNames.length !=
        previousAssociation.foreignPropNames.length) {
      throw ArgumentError(
          'Database keys have inconsistent number of columns.');
    }
  }
}