for now I’m just appending the mongoDBID to a new struct, but I like to propose simply changing the normalizeToStruct to only do the query transformation, otherwise, just returning the object and allowing the structFindKey to throw a more informative exception, if the target isn’t supported?
private function normalizeToStruct( any target ){
if ( isStruct( arguments.target ) ) {
return arguments.target;
}
if ( isQuery( arguments.target ) ) {
return getMetadata( arguments.target ).reduce( ( results, item ) => {
results[ item.name ] = {};
return results;
}, {} );
}
throw( "InvalidTargetType", "The target is not a struct or query" );
}
I’ve been updating Lucee to use the latest testbox, I found a problem introduced with
https://ortussolutions.atlassian.net/browse/TESTBOX-370
This test fails due to the isStruct test introduced, the MongoDBID isn’t a struct but is struct like
https://github.com/lucee/Lucee/blob/6.2/test/datasource/MongoDB.cfc#L119
https://github.com/lucee/extension-mongodb/blob/master/source/java/src/org/lucee/mongodb/MongoDBId.java
https://github.com/lucee/extension-mongodb/blob/master/source/java/src/org/lucee/mongodb/ObjectIdImpl.java
for now I’m just appending the mongoDBID to a new struct, but I like to propose simply changing the normalizeToStruct to only do the query transformation, otherwise, just returning the object and allowing the structFindKey to throw a more informative exception, if the target isn’t supported?
private function normalizeToStruct( any target ){ if ( isStruct( arguments.target ) ) { return arguments.target; } if ( isQuery( arguments.target ) ) { return getMetadata( arguments.target ).reduce( ( results, item ) => { results[ item.name ] = {}; return results; }, {} ); } throw( "InvalidTargetType", "The target is not a struct or query" ); }
https://github.com/Ortus-Solutions/TestBox/blob/development/system/Assertion.cfc#L1456
to
private function normalizeToStruct( any target ){ if ( isQuery( arguments.target ) ) { return getMetadata( arguments.target ).reduce( ( results, item ) => { results[ item.name ] = {}; return results; }, {} ); } return arguments.target; }