You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Defining a mapper to include a key that doesn't exist within the model will throw an exception if the mapper exists inside of the model, and not outside.
Steps to reproduce this issue?
Update the test-harness User model and add the "foo" mapper inside the model and also add optionally it to the list of defaultIncludes.
this.memento = {
// Default properties to serialize
defaultIncludes : [
"userId",
"blogUrl",
"fname:firstName",
"lname:lastName"
"foo" // <--- (optional) This property does not exist in the model
],
// Mappers to serialize the properties
mappers = {
// Add the mapper for the key that doesn't exist.
"foo" : function( _, memento ){
return memento.firstName & " " & memento.lastName;
}
}
};
Now, when you call getMemento() on the object, you will get a missing method error that getFoo can't be found.
Based on what I have discovered by playing around with the test harness, you can define a mapper to a key that doesn't exist if you define the mapper outside the model and specify the name in the list of includes. However, it breaks if the mapper exists inside the model and you use defaultIncludes inside the model or includes outside.
// Mapper outside the model: This works
var result = user.getMemento(
includes = [ "foo" ],
mappers = {
"foo" : function( _, memento ){
return memento.firstName & " " & memento.lastName;
}
}
}
// Mapper inside the model: This does not work
var result = user.getMemento(
includes = [ "foo" ]
}
The only workaround is to explicitly add the property (or virtual attribute if you're using Quick) to your model or define your mappers outside of the model.
The text was updated successfully, but these errors were encountered:
if ( arguments.trustedGetters || structKeyExists( this, "get#item#" ) ) {
try {
thisValue = invoke( this, "get#item#" );
} catch ( any e ) {
// Unless trusted getters is on and there is a mapper for this item rethrow the exception.
if ( !arguments.trustedGetters || !structKeyExists( arguments.mappers, item ) ) {
rethrow;
}
}
// If the key doesn't exist and there is no mapper for the item, go to the next item.
} else if ( !structKeyExists( thisMemento.mappers, item ) ) {
continue;
}
As you can see it does check the mappers. However, do you happen to have trusted getters to TRUE??
Defining a mapper to include a key that doesn't exist within the model will throw an exception if the mapper exists inside of the model, and not outside.
Steps to reproduce this issue?
Update the test-harness
User
model and add the "foo" mapper inside the model and also add optionally it to the list ofdefaultIncludes
.Now, when you call
getMemento()
on the object, you will get a missing method error thatgetFoo
can't be found.Based on what I have discovered by playing around with the test harness, you can define a mapper to a key that doesn't exist if you define the mapper outside the model and specify the name in the list of
includes
. However, it breaks if the mapper exists inside the model and you usedefaultIncludes
inside the model orincludes
outside.The only workaround is to explicitly add the property (or virtual attribute if you're using Quick) to your model or define your mappers outside of the model.
The text was updated successfully, but these errors were encountered: