morphMany<Parent extends RelationalModel<Parent> , Child extends RelationalModel<Child> > function
Relation<Parent, Child>
morphMany<Parent extends RelationalModel<Parent> , Child extends RelationalModel<Child> >(
- RelationalModel<
Child> child, - String foreignKey,
- String typeColumn,
- String typeValue, [
- String? localKey,
- RelationScope? scope,
Implementation
Relation<Parent, Child> morphMany<Parent extends RelationalModel<Parent>, Child extends RelationalModel<Child>>(
RelationalModel<Child> child,
String foreignKey, // e.g. 'subject_uuid'
String typeColumn, // e.g. 'subject_type'
String typeValue, // e.g. 'publisher'
[
String? localKey, // e.g. 'uuid'
RelationScope? scope, // optional extra filtering
]
) {
// Base polymorphic match
RelationScope autoScope;
autoScope = (q) => q.where(typeColumn, typeValue);
// Merge autoScope + userScope
RelationScope? finalScope;
if (scope != null) {
finalScope = (q) => scope(autoScope(q)); // autoScope FIRST → then user scope
} else {
finalScope = autoScope;
}
return hasMany<Parent, Child>(
child,
foreignKey,
localKey,
finalScope,
);
}