UNPKG

@cheetah.js/orm

Version:
29 lines 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ManyToOne = exports.OneToMany = void 0; const constants_1 = require("../constants"); const core_1 = require("@cheetah.js/core"); const utils_1 = require("../utils"); function OneToMany(entity, fkKey) { return (target, propertyKey) => { const existing = core_1.Metadata.get(constants_1.PROPERTIES_RELATIONS, target.constructor) || []; const options = { relation: 'one-to-many', propertyKey, isRelation: true, entity, fkKey, type: core_1.Metadata.getType(target, propertyKey), originalEntity: target.constructor }; options['columnName'] = `${(0, utils_1.toSnakeCase)(propertyKey)}_id`; // @ts-ignore existing.push(options); core_1.Metadata.set(constants_1.PROPERTIES_RELATIONS, existing, target.constructor); }; } exports.OneToMany = OneToMany; function ManyToOne(entity) { return (target, propertyKey) => { const existing = core_1.Metadata.get(constants_1.PROPERTIES_RELATIONS, target.constructor) || []; const options = { relation: 'many-to-one', propertyKey, isRelation: true, entity, type: core_1.Metadata.getType(target, propertyKey), originalEntity: target.constructor }; options['columnName'] = `${(0, utils_1.toSnakeCase)(propertyKey)}_id`; // @ts-ignore existing.push(options); core_1.Metadata.set(constants_1.PROPERTIES_RELATIONS, existing, target.constructor); }; } exports.ManyToOne = ManyToOne; //# sourceMappingURL=one-many.decorator.js.map