hasOneThrough<R extends KhademModel<R> > method
RelationDefinition<KhademModel>
hasOneThrough<R extends KhademModel<R> >({})
Define a "has one through" relationship with clearer parameter names.
Key meanings:
throughForeignKey: column on the through table that points to the parent. Example:users.country_id.relatedForeignKey: column on the related table that points to the through table. Example:posts.user_id.parentLocalKey: column on the parent model used for matching (default:id). Example:countries.id.throughLocalKey: column on the through table used in the JOIN (default:id). Example:users.id.
Implementation
RelationDefinition hasOneThrough<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.hasOneThrough,
localKey: resolvedParentLocalKey,
foreignKey: '',
relatedTable: relatedTable,
factory: factory,
throughTable: throughTable,
firstKey: throughForeignKey,
secondKey: relatedForeignKey,
secondLocalKey: throughLocalKey,
query: query,
);
}