Skip to content

Function: resourcefulHasMany() ​

ts
function resourcefulHasMany<RelatedModel>(
  model: () => RelatedModel,
  options: Partial<
    RelationOptions<RelatedModel, LucidModel, HasOne<RelatedModel, LucidModel>>
  > &
    Partial<ResourcefulRelationshipDefinition<LucidModel>>,
): (target: any, propertyKey: string) => void;

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

Type Parameters ​

Type Parameter
RelatedModel extends LucidModel

Parameters ​

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

class User {
  @resourcefulHasMany(() => Post, { foreignKey: "user_id" })
  public posts: HasMany<typeof Post>;
}