Skip to content

Function: resourcefulManyToMany() ​

ts
function resourcefulManyToMany<RelatedModel>(
  model: () => RelatedModel,
  options: Partial<ManyToManyRelationOptions<ManyToMany<RelatedModel>>> &
    Partial<ResourcefulRelationshipDefinition<LucidModel>>,
): (target: any, propertyKey: string) => void;

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

Type Parameters ​

Type Parameter
RelatedModel extends LucidModel

Parameters ​

ParameterTypeDescription
model() => RelatedModelFunction returning the related model class.
optionsPartial<ManyToManyRelationOptions<ManyToMany<RelatedModel>>> & Partial<ResourcefulRelationshipDefinition<LucidModel>>ManyToMany 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 { resourcefulManyToMany } from "@nhtio/lucid-resourceful";

class User {
  @resourcefulManyToMany(() => Role, { pivotTable: "role_user" })
  public roles: ManyToMany<typeof Role>;
}