diff --git a/CHANGELOG.md b/CHANGELOG.md index 2459904..ab64a31 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 66bf48f..a94da1f 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});