removed bad code
Former-commit-id: c67350b4ef1e16b89594f0e7932baed74a3bf414
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user