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
| Parameter | Type | Description |
|---|---|---|
model | () => RelatedModel | Function returning the related model class. |
options | Partial<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
| Parameter | Type |
|---|---|
target | any |
propertyKey | string |
Returns
void
Example
ts
import { resourcefulBelongsTo } from "@nhtio/lucid-resourceful";
class Post {
@resourcefulBelongsTo(() => User, { foreignKey: "user_id" })
public user: User;
}