UNPKG

adonis-odm

Version:

A comprehensive MongoDB ODM for AdonisJS with Lucid-style API, type-safe relationships, embedded documents, and transaction support

55 lines (54 loc) 1.59 kB
/** * RELATIONSHIP DECORATORS * * These decorators are used to define relationships on model classes * and provide the metadata needed for automatic type inference. */ /** * HasOne relationship decorator */ export function hasOne(relatedModel, options) { return function (target, propertyKey) { // Store relationship metadata for runtime use if (!target.constructor.$relationships) { target.constructor.$relationships = {}; } target.constructor.$relationships[propertyKey] = { type: 'hasOne', relatedModel, options: options || {}, }; }; } /** * HasMany relationship decorator */ export function hasMany(relatedModel, options) { return function (target, propertyKey) { // Store relationship metadata for runtime use if (!target.constructor.$relationships) { target.constructor.$relationships = {}; } target.constructor.$relationships[propertyKey] = { type: 'hasMany', relatedModel, options: options || {}, }; }; } /** * BelongsTo relationship decorator */ export function belongsTo(relatedModel, options) { return function (target, propertyKey) { // Store relationship metadata for runtime use if (!target.constructor.$relationships) { target.constructor.$relationships = {}; } target.constructor.$relationships[propertyKey] = { type: 'belongsTo', relatedModel, options: options || {}, }; }; }