match method

  1. @override
List<KhademModel> match(
  1. List<KhademModel> models,
  2. List<Related> results,
  3. 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, Related>{};

  for (final result in results) {
    final key = result.getAttribute('khadem_through_key');
    if (key != null) {
      dictionary[key] = result;
    }
  }

  for (final model in models) {
    final key = model.getAttribute(localKey);
    if (dictionary.containsKey(key)) {
      model.setRelation(relation, dictionary[key]);
    }
  }

  return models;
}