Skip to content

Function: resourcefulHasManyThrough()

ts
function resourcefulHasManyThrough<RelatedModel>(
  model: [() => RelatedModel, () => LucidModel],
  options: Partial<HasManyThroughRelationOptions<RelatedModel>> &
    Partial<ResourcefulRelationshipDefinition<LucidModel>>,
): (target: any, propertyKey: string) => void;

Decorator to define a resourceful hasManyThrough relationship on a Lucid model property.

Type Parameters

Type Parameter
RelatedModel extends LucidModel

Parameters

ParameterTypeDescription
model[() => RelatedModel, () => LucidModel]Tuple of functions returning the related model and through model classes.
optionsPartial<HasManyThroughRelationOptions<RelatedModel>> & Partial<ResourcefulRelationshipDefinition<LucidModel>>HasManyThrough relationship options and resourceful relationship definition.

Returns

Property decorator function.

ts
(target: any, propertyKey: string): void;

Parameters

ParameterType
targetany
propertyKeystring

Returns

void

Example

ts
import { resourcefulHasManyThrough } from "@nhtio/lucid-resourceful";

class User {
  @resourcefulHasManyThrough([() => Role, () => UserRolePivot], {
    foreignKey: "user_id",
  })
  public roles: HasManyThrough<typeof Role>;
}