From 897b9bfc2270843cfe76195378432475ac216e79 Mon Sep 17 00:00:00 2001 From: Jelle De Loecker Date: Sat, 16 Mar 2024 16:20:03 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Use=20the=20correct=20model=20na?= =?UTF-8?q?me=20(instead=20of=20constructor=20name)=20for=20schemas=20of?= =?UTF-8?q?=20a=20Route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + lib/class/route.js | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2459904f..ab64a311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fix `Alchemy.Client.Schema.isSchema(value)` never returning true * Add support for asynchronous custom schema values in the `Schema` field class * Make the `Controller#model` getter try to get the model from the same namespace +* Use the correct model name (instead of constructor name) for schemas of a Route ## 1.4.0-alpha.3 (2024-02-25) diff --git a/lib/class/route.js b/lib/class/route.js index 66bf48f6..a94da1f2 100644 --- a/lib/class/route.js +++ b/lib/class/route.js @@ -141,7 +141,7 @@ Route.setProperty(function has_type_class_checks() { * * @author Jelle De Loecker * @since 1.3.7 - * @version 1.3.7 + * @version 1.4.0 * * @return {Schema} */ @@ -159,7 +159,6 @@ Route.enforceProperty(function schema(new_value) { added_fields = {}, prefix, param, - model_constructor, definition; new_value = alchemy.createSchema(); @@ -172,11 +171,11 @@ Route.enforceProperty(function schema(new_value) { } for (param of definition.param_definitions) { - model_constructor = param.model_constructor; + let model_name = param.model_constructor?.model_name; - if (model_constructor) { + if (model_name) { - if (added_models[model_constructor.name]) { + if (added_models[model_name]) { continue; } @@ -184,10 +183,10 @@ Route.enforceProperty(function schema(new_value) { continue; } - added_models[model_constructor.name] = true; + added_models[model_name] = true; try { - new_value.belongsTo(model_constructor.name); + new_value.belongsTo(model_name); } catch (err) { // Ignored alchemy.distinctProblem('route-schema-' + this.name, 'Route schema error', {error: err});