ModelEntity.fromMap constructor

ModelEntity.fromMap(
  1. Map<String, dynamic> data, {
  2. ModelInfo? model,
  3. bool check = true,
})

Implementation

ModelEntity.fromMap(Map<String, dynamic> data,
    {ModelInfo? model, bool check = true})
    : _model = model,
      id = IdUid.fromString(data[ModelEntityKey.id] as String?),
      lastPropertyId =
          IdUid.fromString(data[ModelEntityKey.lastPropertyId] as String?),
      uidRequest = data[ModelEntityKey.uidRequest] as bool? ?? false,
      _properties = [],
      _relations = [],
      _backlinks = [] {
  name = data[ModelEntityKey.name] as String?;
  externalName = data[ModelEntityKey.externalName] as String?;
  flags = data[ModelEntityKey.flags] as int? ?? 0;

  final properties = data[ModelEntityKey.properties] as List;
  for (final p in properties) {
    _properties.add(ModelProperty.fromMap(p as Map<String, dynamic>, this));
  }

  final relations = data[ModelEntityKey.relations] as List?;
  if (relations != null) {
    for (final p in relations) {
      _relations.add(ModelRelation.fromMap(p as Map<String, dynamic>));
    }
  }

  final backlinks = data[ModelEntityKey.backlinks] as List?;
  if (backlinks != null) {
    for (final p in backlinks) {
      _backlinks.add(ModelBacklink.fromMap(p as Map<String, dynamic>));
    }
  }

  if (data[ModelEntityKey.constructorParams] != null) {
    constructorParams =
        (data[ModelEntityKey.constructorParams] as List<dynamic>)
            .map((dynamic e) => e as String)
            .toList(growable: false);
  }

  if (check) validate();

  _idProperty = this
      .properties
      .singleWhere((p) => (p.flags & OBXPropertyFlags.ID) != 0);
}