get method
Executes and returns all matching rows.
Implementation
@override
Future<List<T>> get() async {
_applyDefaultWithCountIfNeeded();
final sql = grammar.compileSelect(_getQueryComponents());
final result = await connection.execute(sql, bindings);
List<T> items;
if (modelFactory != null) {
items = (result.data as List).map((row) => modelFactory!(row)).toList();
} else {
items = (result.data as List).cast<T>().toList();
}
// Eager Loading
if (items.isNotEmpty && items.first is KhademModel) {
final models = items.cast<KhademModel>();
final firstModel = models.first;
final relations = <dynamic>[];
if (_withOnly.isNotEmpty) {
relations.addAll(_withOnly);
} else {
// Add default relations
relations.addAll(firstModel.withRelations);
// Add requested relations
relations.addAll(_with);
// Remove excluded relations
// Note: This simple removal only works for string matches.
// Complex relation definitions might need more robust handling.
relations.removeWhere((r) => _without.contains(r.toString()));
}
if (relations.isNotEmpty) {
await EagerLoader.loadRelations(models, relations);
}
}
return items;
}