createRelation method

ModelRelation createRelation(
  1. String name, [
  2. int uid = 0
])

Implementation

ModelRelation createRelation(String name, [int uid = 0]) {
  final id = model.lastRelationId.id + 1;
  if (uid != 0 && model.containsUid(uid)) {
    throw StateError('uid already exists: $uid');
  }
  final uniqueUid = uid == 0 ? model.generateUid() : uid;

  final relation = ModelRelation.create(IdUid(id, uniqueUid), name);
  relations.add(relation);
  model.lastRelationId = relation.id;

  return relation;
}