Skip to content

Function: resourcefulBelongsTo() ​

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

Decorator to define a resourceful belongsTo 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 { resourcefulBelongsTo } from "@nhtio/lucid-resourceful";

class Post {
  @resourcefulBelongsTo(() => User, { foreignKey: "user_id" })
  public user: User;
}