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_through_key');
if (key != null) {
if (!dictionary.containsKey(key)) {
dictionary[key] = [];
}
dictionary[key]!.add(result);
}
// Clean up the temporary attribute
// result.unsetAttribute('khadem_through_key'); // If such method exists
}
for (final model in models) {
final key = model.getAttribute(localKey);
if (dictionary.containsKey(key)) {
model.setRelation(relation, dictionary[key]);
}
}
return models;
}