@spinajs/orm
Advanced tools
Comparing version 2.0.232 to 2.0.233
@@ -11,2 +11,3 @@ "use strict"; | ||
const exceptions_1 = require("@spinajs/exceptions"); | ||
const orm_js_1 = require("./orm.js"); | ||
exports.MODEL_DESCTRIPTION_SYMBOL = Symbol.for('MODEL_DESCRIPTOR'); | ||
@@ -333,3 +334,3 @@ exports.MIGRATION_DESCRIPTION_SYMBOL = Symbol.for('MIGRATION_DESCRIPTOR'); | ||
Factory: options?.factory ? options.factory : null, | ||
RelationClass: options?.type ? options.type : () => di_1.DI.resolve("__orm_relation_has_many_factory__", [type]), | ||
RelationClass: options?.type ? options.type : () => di_1.DI.resolve('__orm_relation_has_many_factory__', [type]), | ||
}); | ||
@@ -362,5 +363,3 @@ }); | ||
return extractDecoratorDescriptor((model, target, propertyKey) => { | ||
const targetModelDescriptor = (0, model_js_1.extractModelDescriptor)(targetModel); | ||
let type = Reflect.getMetadata('design:type', target, propertyKey); | ||
model.Relations.set(propertyKey, { | ||
const descriptor = { | ||
Name: propertyKey, | ||
@@ -372,10 +371,38 @@ Recursive: false, | ||
TargetModel: null, | ||
ForeignKey: options?.targetModelPKey ?? targetModelDescriptor.PrimaryKey, | ||
ForeignKey: '', | ||
// ForeignKey: options?.targetModelPKey ?? targetModelDescriptor.PrimaryKey, | ||
PrimaryKey: options?.sourceModelPKey ?? model.PrimaryKey, | ||
JunctionModel: junctionModel, | ||
JunctionModelTargetModelFKey_Name: options?.junctionModelTargetPk ?? `${targetModelDescriptor.Name.toLowerCase()}_id`, | ||
// JunctionModelTargetModelFKey_Name: options?.junctionModelTargetPk ?? `${targetModelDescriptor.Name.toLowerCase()}_id`, | ||
JunctionModelTargetModelFKey_Name: '', | ||
JunctionModelSourceModelFKey_Name: options?.junctionModelSourcePk ?? `${model.Name.toLowerCase()}_id`, | ||
RelationClass: options?.type ? options.type : () => di_1.DI.resolve("__orm_relation_has_many_to_many_factory__", [type]), | ||
RelationClass: options?.type ? options.type : () => di_1.DI.resolve('__orm_relation_has_many_to_many_factory__', [type]), | ||
Factory: options ? options.factory : null, | ||
}); | ||
}; | ||
// HACK: | ||
// we should use ForwardRefFunction as targetModel type | ||
// and lazy resolve foreginKey and JunctionModelTargetModelFKey_Name at runtime | ||
// using of getters is temporary ??? too much code change for now | ||
if (typeof targetModel === 'string') { | ||
const getModel = function () { | ||
return (0, model_js_1.extractModelDescriptor)(di_1.DI.get(orm_js_1.Orm).Models.find((x) => x.name === targetModel).type); | ||
}; | ||
Object.defineProperty(descriptor, 'ForeignKey', { | ||
get: function () { | ||
return options?.targetModelPKey ?? getModel().PrimaryKey; | ||
}, | ||
}); | ||
Object.defineProperty(descriptor, 'JunctionModelTargetModelFKey_Name', { | ||
get: function () { | ||
options?.junctionModelTargetPk ?? `${getModel().Name.toLowerCase()}_id`; | ||
}, | ||
}); | ||
} | ||
else { | ||
const targetModelDescriptor = (0, model_js_1.extractModelDescriptor)(targetModel); | ||
descriptor.ForeignKey = options?.targetModelPKey ?? targetModelDescriptor.PrimaryKey; | ||
descriptor.JunctionModelTargetModelFKey_Name = options?.junctionModelTargetPk ?? `${targetModelDescriptor.Name.toLowerCase()}_id`; | ||
} | ||
let type = Reflect.getMetadata('design:type', target, propertyKey); | ||
model.Relations.set(propertyKey, descriptor); | ||
}); | ||
@@ -430,3 +457,3 @@ } | ||
Options: { | ||
TypeColumn: typeColumn ?? "Type", | ||
TypeColumn: typeColumn ?? 'Type', | ||
}, | ||
@@ -433,0 +460,0 @@ }); |
@@ -8,2 +8,3 @@ /* eslint-disable prettier/prettier */ | ||
import { InvalidOperation, InvalidArgument } from '@spinajs/exceptions'; | ||
import { Orm } from './orm.js'; | ||
export const MODEL_DESCTRIPTION_SYMBOL = Symbol.for('MODEL_DESCRIPTOR'); | ||
@@ -313,3 +314,3 @@ export const MIGRATION_DESCRIPTION_SYMBOL = Symbol.for('MIGRATION_DESCRIPTOR'); | ||
Factory: options?.factory ? options.factory : null, | ||
RelationClass: options?.type ? options.type : () => DI.resolve("__orm_relation_has_many_factory__", [type]), | ||
RelationClass: options?.type ? options.type : () => DI.resolve('__orm_relation_has_many_factory__', [type]), | ||
}); | ||
@@ -340,5 +341,3 @@ }); | ||
return extractDecoratorDescriptor((model, target, propertyKey) => { | ||
const targetModelDescriptor = extractModelDescriptor(targetModel); | ||
let type = Reflect.getMetadata('design:type', target, propertyKey); | ||
model.Relations.set(propertyKey, { | ||
const descriptor = { | ||
Name: propertyKey, | ||
@@ -350,10 +349,38 @@ Recursive: false, | ||
TargetModel: null, | ||
ForeignKey: options?.targetModelPKey ?? targetModelDescriptor.PrimaryKey, | ||
ForeignKey: '', | ||
// ForeignKey: options?.targetModelPKey ?? targetModelDescriptor.PrimaryKey, | ||
PrimaryKey: options?.sourceModelPKey ?? model.PrimaryKey, | ||
JunctionModel: junctionModel, | ||
JunctionModelTargetModelFKey_Name: options?.junctionModelTargetPk ?? `${targetModelDescriptor.Name.toLowerCase()}_id`, | ||
// JunctionModelTargetModelFKey_Name: options?.junctionModelTargetPk ?? `${targetModelDescriptor.Name.toLowerCase()}_id`, | ||
JunctionModelTargetModelFKey_Name: '', | ||
JunctionModelSourceModelFKey_Name: options?.junctionModelSourcePk ?? `${model.Name.toLowerCase()}_id`, | ||
RelationClass: options?.type ? options.type : () => DI.resolve("__orm_relation_has_many_to_many_factory__", [type]), | ||
RelationClass: options?.type ? options.type : () => DI.resolve('__orm_relation_has_many_to_many_factory__', [type]), | ||
Factory: options ? options.factory : null, | ||
}); | ||
}; | ||
// HACK: | ||
// we should use ForwardRefFunction as targetModel type | ||
// and lazy resolve foreginKey and JunctionModelTargetModelFKey_Name at runtime | ||
// using of getters is temporary ??? too much code change for now | ||
if (typeof targetModel === 'string') { | ||
const getModel = function () { | ||
return extractModelDescriptor(DI.get(Orm).Models.find((x) => x.name === targetModel).type); | ||
}; | ||
Object.defineProperty(descriptor, 'ForeignKey', { | ||
get: function () { | ||
return options?.targetModelPKey ?? getModel().PrimaryKey; | ||
}, | ||
}); | ||
Object.defineProperty(descriptor, 'JunctionModelTargetModelFKey_Name', { | ||
get: function () { | ||
options?.junctionModelTargetPk ?? `${getModel().Name.toLowerCase()}_id`; | ||
}, | ||
}); | ||
} | ||
else { | ||
const targetModelDescriptor = extractModelDescriptor(targetModel); | ||
descriptor.ForeignKey = options?.targetModelPKey ?? targetModelDescriptor.PrimaryKey; | ||
descriptor.JunctionModelTargetModelFKey_Name = options?.junctionModelTargetPk ?? `${targetModelDescriptor.Name.toLowerCase()}_id`; | ||
} | ||
let type = Reflect.getMetadata('design:type', target, propertyKey); | ||
model.Relations.set(propertyKey, descriptor); | ||
}); | ||
@@ -405,3 +432,3 @@ } | ||
Options: { | ||
TypeColumn: typeColumn ?? "Type", | ||
TypeColumn: typeColumn ?? 'Type', | ||
}, | ||
@@ -408,0 +435,0 @@ }); |
{ | ||
"name": "@spinajs/orm", | ||
"version": "2.0.232", | ||
"version": "2.0.233", | ||
"description": "framework orm module", | ||
@@ -58,6 +58,6 @@ "main": "lib/cjs/index.js", | ||
"dependencies": { | ||
"@spinajs/configuration-common": "^2.0.232", | ||
"@spinajs/di": "^2.0.232", | ||
"@spinajs/exceptions": "^2.0.232", | ||
"@spinajs/log-common": "^2.0.232", | ||
"@spinajs/configuration-common": "^2.0.233", | ||
"@spinajs/di": "^2.0.233", | ||
"@spinajs/exceptions": "^2.0.233", | ||
"@spinajs/log-common": "^2.0.233", | ||
"glob": "^8.1.0", | ||
@@ -64,0 +64,0 @@ "glob-to-regexp": "^0.4.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1286211
17243