removed bad code

Former-commit-id: c67350b4ef1e16b89594f0e7932baed74a3bf414
This commit is contained in:
Ben
2022-02-14 17:13:49 +00:00
parent b2652d944b
commit 7eb47c22e4
3 changed files with 5 additions and 48 deletions

View File

@@ -96,47 +96,9 @@ class PSQLObjectRelation {
*/
// TODO: Make this more maintainable
resolveDepends() {
for (const dummyModelName in this.dummyModels) {
const dummyModel = this.dummyModels[dummyModelName];
if (!this.models[dummyModel.name]) {
Logger.Error(`Model ${dummyModel.name} does not exist, cannot resolve dependancies`);
continue;
}
for (const propertyName in dummyModel.properties)
{
const property = dummyModel.properties[propertyName];
if (property.type !== DataTypes.INHERET) {
continue;
}
if (property.referers.length === 0 || property.referers[0] === '') {
Logger.Error(`Model ${dummyModel.name} has a property ${propertyName} with no referers`);
continue;
}
for (const referer of property.referers) {
if (!this.models[referer]) {
Logger.Error(`Model ${dummyModel.name} has a property ${propertyName} with a referer ${referer} that does not exist`);
continue;
}
// TODO: Make more generic
const relaventConstraints = this.models[referer].properties[dummyModelName].constraints;
for (const constraint in relaventConstraints) {
if (typeof relaventConstraints[constraint] === 'object') {
this.models[referer].properties[dummyModelName].constraints[constraint] = DataConstraints.FOREIGN_KEY_REF(dummyModel.name);
Logger.Database(`Model ${referer} has a property ${dummyModel.name} which was resolved to a foreign key`);
break;
}
}
this.dummyModels.splice(this.dummyModels.indexOf(dummyModel), 1);
}
}
}
}
/**

View File

@@ -21,19 +21,14 @@ class Model {
Logger.Database(`Model ${name} created, with properties: ${JSON.stringify(properties)}`);
}
/**
* @function property
* @description Gets a property from the model
* @param {string} name - The name of the target property
*/
property(name, referer = '') {
property(name) {
if (this.dummy) {
if (this.properties[name]) {
this.properties[name].referers.push(referer);
// THIS;
}
this.properties[name] = {
type: DataTypes.INHERET,
referers: [referer],
referers: [],
constraints: [],
dummy: true,
};

View File

@@ -10,7 +10,7 @@ function init() {
},
catagory: {
type: DataTypes.INTEGER,
constraints: [DataConstraints.FOREIGN_KEY_REF(ORM.model('catagory').property('id', 'lego_brick'))],
constraints: [DataConstraints.FOREIGN_KEY_REF(ORM.model('catagory').property('id'))],
},
date_released: DataTypes.TIMESTAMP,
dimenions_x: DataTypes.DECIMAL,