@dazejs/framework
Version:
Daze.js - A powerful web framework for Node.js
69 lines • 2.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BelongsToMany = exports.HasMany = exports.BelongsTo = exports.HasOne = void 0;
const HasOne = function (fn, options = {}) {
return function (target, propertyKey) {
var _a;
if (typeof propertyKey !== 'string')
return;
const relations = (_a = Reflect.getMetadata('relations', target.constructor)) !== null && _a !== void 0 ? _a : new Map();
relations.set(propertyKey, {
type: 'hasOne',
entityFn: fn,
foreignKey: options.foreignKey,
localKey: options.localKey
});
Reflect.defineMetadata('relations', relations, target.constructor);
};
};
exports.HasOne = HasOne;
const BelongsTo = function (fn, options = {}) {
return function (target, propertyKey) {
var _a;
if (typeof propertyKey !== 'string')
return;
const relations = (_a = Reflect.getMetadata('relations', target.constructor)) !== null && _a !== void 0 ? _a : new Map();
relations.set(propertyKey, {
type: 'belongsTo',
entityFn: fn,
foreignKey: options.foreignKey,
localKey: options.localKey
});
Reflect.defineMetadata('relations', relations, target.constructor);
};
};
exports.BelongsTo = BelongsTo;
const HasMany = function (fn, options = {}) {
return function (target, propertyKey) {
var _a;
if (typeof propertyKey !== 'string')
return;
const relations = (_a = Reflect.getMetadata('relations', target.constructor)) !== null && _a !== void 0 ? _a : new Map();
relations.set(propertyKey, {
type: 'hasMany',
entityFn: fn,
foreignKey: options.foreignKey,
localKey: options.localKey
});
Reflect.defineMetadata('relations', relations, target.constructor);
};
};
exports.HasMany = HasMany;
const BelongsToMany = function (fn, options = {}) {
return function (target, propertyKey) {
var _a;
if (typeof propertyKey !== 'string')
return;
const relations = (_a = Reflect.getMetadata('relations', target.constructor)) !== null && _a !== void 0 ? _a : new Map();
relations.set(propertyKey, {
type: 'belongsToMany',
entityFn: fn,
pivot: options.pivot,
foreignPivotKey: options.foreignPivotKey,
relatedPivotKey: options.relatedPivotKey
});
Reflect.defineMetadata('relations', relations, target.constructor);
};
};
exports.BelongsToMany = BelongsToMany;
//# sourceMappingURL=relation.js.map