match method
List<KhademModel>
match(
- List<
KhademModel> models, - List<
Related> results, - String relation
override
Match the eagerly loaded results to their parents.
Implementation
@override
List<KhademModel> match(
List<KhademModel> models,
List<Related> results,
String relation,
) {
final dictionary = <dynamic, List<Related>>{};
for (final result in results) {
final key = result.getAttribute('khadem_pivot_foreign_key');
if (key != null) {
(dictionary[key] ??= <Related>[]).add(result);
}
}
for (final model in models) {
final key = model.getAttribute(parentKey);
if (dictionary.containsKey(key)) {
model.setRelation(relation, dictionary[key]);
} else {
model.setRelation(relation, <Related>[]);
}
}
return models;
}