diff --git a/CHANGELOG.md b/CHANGELOG.md index d13bf7f..220b1fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.4.0-alpha.8 (WIP) + +* Fix `_modelInstance` cache when keys are not strings + ## 1.4.0-alpha.7 (2024-10-10) * End requests with an error when parsing posted body contents fail diff --git a/lib/app/helper_model/model.js b/lib/app/helper_model/model.js index f31c9ac..183c5b2 100644 --- a/lib/app/helper_model/model.js +++ b/lib/app/helper_model/model.js @@ -680,6 +680,11 @@ Model.setMethod(function getAliasModel(alias) { config = this.schema.associations[alias]; } + // @TODO: associated fields with an alias name inside a nested schema + // somehow breaks! Should be looked in to? + // Workaround: set `recursive: 0` on the root schema field + // console.log('Alias:', alias, 'config:', config, this.schema); + if (config) { result = this.getModel(config.modelName); } else { diff --git a/lib/core/base.js b/lib/core/base.js index 1ee902c..e884906 100644 --- a/lib/core/base.js +++ b/lib/core/base.js @@ -564,7 +564,7 @@ Base.setMethod(function attachConduit(conduit) { * * @author Jelle De Loecker * @since 0.3.0 - * @version 1.1.8 + * @version 1.4.0 * * @param {string} name The name of the model to get * @param {boolean} init Initialize the class [true] @@ -597,9 +597,9 @@ Base.setMethod(function getModel(name, init, options) { if (options.cache !== false) { if (!this._modelInstances) { - this._modelInstances = {}; + this._modelInstances = new Map(); } else { - instance = this._modelInstances[name]; + instance = this._modelInstances.get(name); } } @@ -622,7 +622,7 @@ Base.setMethod(function getModel(name, init, options) { } if (options.cache !== false) { - this._modelInstances[name] = instance; + this._modelInstances.set(name, instance); } return instance; diff --git a/package.json b/package.json index ea950be..23a245f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "alchemymvc", "description": "MVC framework for Node.js", - "version": "1.4.0-alpha.7", + "version": "1.4.0-alpha.8", "author": "Jelle De Loecker ", "keywords": [ "alchemy",