encodeValue method

  1. @override
Object? encodeValue(
  1. ModelDB db,
  2. Object? value, {
  3. bool forComparison = false,
})
override

Implementation

@override
Object? encodeValue(ModelDB db, Object? value, {bool forComparison = false}) {
  if (forComparison) {
    // If we have comparison of list properties (i.e. repeated property names)
    // the comparison object must not be a list, but the value itself.
    // i.e.
    //
    //   class Article {
    //      ...
    //      @ListProperty(StringProperty())
    //      List<String> tags;
    //      ...
    //   }
    //
    // should be queried via
    //
    //   await db.query(Article, 'tags=', "Dart").toList();
    //
    // So the [value] for the comparison is of type `String` and not
    // `List<String>`!
    return subProperty.encodeValue(db, value, forComparison: true);
  }

  if (value == null) return null;
  var list = value as List;
  if (list.isEmpty) return null;
  if (list.length == 1) return subProperty.encodeValue(db, list[0]);
  return list.map((value) => subProperty.encodeValue(db, value)).toList();
}