findWhere method
Implementation
Future<List<T>> findWhere(
{Database? database,
String? whereParameters,
String? orderParameters,
List<String>? fields,
List<ColumnRelation>? relations}) async {
final Database db = database != null ? database : this.database;
final dataResults = (await db.query(this.entity.tableName,
where: whereParameters, orderBy: orderParameters, columns: fields));
final List<String> dataIds =
dataResults.map((dataResult) => dataResult['id'].toString()).toList();
final relationData = relations != null
? await this.findRelationByParent(
relations: relations,
dataIds: dataIds,
orderParameters: orderParameters,
database: db)
: [];
return dataResults.map((e) {
Map<String, dynamic> resultMap = {...e};
(relationData ?? []).forEach((relationDataItem) {
final availableRelationData = (relationDataItem['data'] ?? [])
.where((relationItem) =>
relationItem[relationDataItem['referencedColumn']] ==
resultMap['id'])
.toList();
resultMap[relationDataItem['relation']] = availableRelationData;
});
return getObject<T>(resultMap);
}).toList();
}