UNPKG

miter

Version:

A typescript web framework based on ExpressJs based loosely on SailsJs

28 lines 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const has_many_1 = require("../../../metadata/orm/associations/has-many"); function isStaticModelT(test) { return test && !!test.db; } function isForeignModelSource(test) { return test && (isStaticModelT(test) || !!test.modelName || !!test.tableName || typeof test === 'function'); } function HasMany(propMeta) { let meta = {}; if (isForeignModelSource(propMeta)) meta = { foreignModel: propMeta }; else meta = propMeta; return function (model, propertyName) { if (!isForeignModelSource(meta.foreignModel)) { throw new Error(`Cannot infer relation type for has-many association in ${model.name || model}.${propertyName}.`); } meta.as = propertyName; let props = Reflect.getOwnMetadata(has_many_1.ModelHasManyAssociationsSym, model) || []; props.push(propertyName); Reflect.defineMetadata(has_many_1.ModelHasManyAssociationsSym, props, model); Reflect.defineMetadata(has_many_1.HasManyMetadataSym, meta, model, propertyName); }; } exports.HasMany = HasMany; //# sourceMappingURL=has-many.decorator.js.map