hasManyThrough<R extends KhademModel<R>> method

RelationDefinition<KhademModel> hasManyThrough<R extends KhademModel<R>>({
  1. required String throughTable,
  2. required String throughForeignKey,
  3. required String relatedForeignKey,
  4. required String relatedTable,
  5. required R factory(),
  6. String? parentLocalKey,
  7. String throughLocalKey = 'id',
  8. dynamic query(
    1. QueryBuilderInterface
    )?,
})

Define a "has many through" relationship with clearer parameter names.

See hasOneThroughVia for the key meanings; the mapping is identical, but this relation returns a list of related models.

Implementation

RelationDefinition hasManyThrough<R extends KhademModel<R>>({
  required String throughTable,
  required String throughForeignKey,
  required String relatedForeignKey,
  required String relatedTable,
  required R Function() factory,
  String? parentLocalKey,
  String throughLocalKey = 'id',
  Function(QueryBuilderInterface)? query,
}) {
  final resolvedParentLocalKey =
      parentLocalKey ?? (this as KhademModel).primaryKey;
  return RelationDefinition<R>(
    type: RelationType.hasManyThrough,
    localKey: resolvedParentLocalKey,
    foreignKey: '',
    relatedTable: relatedTable,
    factory: factory,
    throughTable: throughTable,
    firstKey: throughForeignKey,
    secondKey: relatedForeignKey,
    secondLocalKey: throughLocalKey,
    query: query,
  );
}