Skip to content

Commit

Permalink
🐛 Fix _modelInstance cache when keys are not strings
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Oct 19, 2024
1 parent e647767 commit 59e82a4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/app/helper_model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions lib/core/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ Base.setMethod(function attachConduit(conduit) {
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @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]
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <jelle@elevenways.be>",
"keywords": [
"alchemy",
Expand Down

0 comments on commit 59e82a4

Please sign in to comment.