diff --git a/src/database/psql-entity-framework/entity-relationships.js b/src/database/psql-entity-framework/entity-relationships.js index 6a5e80f..f98c0b2 100644 --- a/src/database/psql-entity-framework/entity-relationships.js +++ b/src/database/psql-entity-framework/entity-relationships.js @@ -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); - } - } - } } /** diff --git a/src/database/psql-entity-framework/model.js b/src/database/psql-entity-framework/model.js index 3ddbd77..62d0762 100644 --- a/src/database/psql-entity-framework/model.js +++ b/src/database/psql-entity-framework/model.js @@ -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, }; diff --git a/src/models/lego-brick.js b/src/models/lego-brick.js index 1a98f39..57717d2 100644 --- a/src/models/lego-brick.js +++ b/src/models/lego-brick.js @@ -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,