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['id'] as String?),
      lastPropertyId = IdUid.fromString(data['lastPropertyId'] as String?),
      uidRequest = data['uidRequest'] as bool? ?? false,
      _properties = [],
      _relations = [],
      _backlinks = [] {
  name = data['name'] as String?;
  flags = data['flags'] as int? ?? 0;

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

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

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

  if (data['constructorParams'] != null) {
    constructorParams = (data['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);
}