Model.translateAlias doesn't iterate through sub-Schemas if the key wasn't an alias
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
When using Model.translateAlias
, if you have a not aliased key that refers to a sub-schema, it will not be picked up to translate keys further along in the key
If the current behavior is a bug, please provide the steps to reproduce.
- Create a
FirstSchema
, where the top level field does not have an alias and refers to aSubSchema
- Inside the
SubSchema
, use aliases - Perform a
model(FirstSchema).translateAlias()
and see that theSubSchema
keys are not translated
The current translate
function uses this iterative loop
// in model.js, Model.translateAlias()
for (const i in fieldKeys) {
const name = fieldKeys[i];
if (currentSchema && currentSchema.aliases[name]) {
alias = currentSchema.aliases[name];
// Alias found,
translated.push(alias);
} else {
// Alias not found, so treat as un-aliased key
// This is where this problem is, since we do not push name to alias
translated.push(name);
}
// Check if aliased path is a schema
// If the key wasn't aliased, we have no way to find the subschema
if (currentSchema && currentSchema.paths[alias]) {
currentSchema = currentSchema.paths[alias].schema;
}
else
currentSchema = null;
}
What is the expected behavior? I propose a one line fix
for (const i in fieldKeys) {
const name = fieldKeys[i];
if (currentSchema && currentSchema.aliases[name]) {
alias = currentSchema.aliases[name];
// Alias found,
translated.push(alias);
} else {
// Alias not found, so treat as un-aliased key
// Here
alias = name;
translated.push(name);
}
// Check if aliased path is a schema
if (currentSchema && currentSchema.paths[alias]) {
currentSchema = currentSchema.paths[alias].schema;
}
else
currentSchema = null;
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Solved: SQL Server - "unable to translate alias" when I sa...
I checked the existing data connections and found one in the list that matched the server\database my locally created alias was using, so...
Read more >Is there an inverse of the mongoose model.translateAliases ...
In my case aggregate project would not work as I am dynamically ... toObject({ virtuals: true }) which should return the alias keys...
Read more >draft-ietf-ldapbis-protocol-31.txt
Protocol Model The general model adopted by this protocol is one of clients ... to locate the named object, it SHALL NOT perform...
Read more >common information model (cim) infrastructure specification
The DMTF Common Information Model (CIM) Infrastructure is an approach to the management of systems and networks that applies the basic ...
Read more >History - Apache Calcite
New behavior: The Project operator is not transformed and the rule becomes NOOP. Compatibility: This release is tested on Linux, macOS, Microsoft Windows; ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, the
Syntax
schema has an alias on it that should be observed regardless of where it is on a parent schema’s definition. The test case I gave is a direct edit of the test case that already exists inmodel.translateAliases.test.js
to remove the alias ofd
todot
. This then prevents thesyntax
>s
alias from resolving.