Skip to content

Commit ee24b38

Browse files
committed
Add BoxLang metadata regressions and compatibility fixes
1 parent 8ec9a94 commit ee24b38

2 files changed

Lines changed: 65 additions & 29 deletions

File tree

models/BaseEntity.cfc

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,10 +2729,20 @@ component accessors="true" {
27292729
var meta = {};
27302730
meta[ "originalMetadata" ] = util.getInheritedMetadata( this );
27312731
meta[ "localMetadata" ] = getMetadata( this );
2732+
var hasAccessorsMetadata = false;
2733+
if ( meta.localMetadata.keyExists( "accessors" ) ) {
2734+
hasAccessorsMetadata = lCase( trim( meta.localMetadata.accessors & "" ) ) == "true";
2735+
}
2736+
// BoxLang 1.11 exposes component metadata attributes inside `annotations`.
27322737
if (
2733-
!meta[ "localMetadata" ].keyExists( "accessors" ) ||
2734-
meta[ "localMetadata" ].accessors == false
2738+
!hasAccessorsMetadata &&
2739+
meta.localMetadata.keyExists( "annotations" ) &&
2740+
isStruct( meta.localMetadata.annotations ) &&
2741+
meta.localMetadata.annotations.keyExists( "accessors" )
27352742
) {
2743+
hasAccessorsMetadata = lCase( trim( meta.localMetadata.annotations.accessors & "" ) ) == "true";
2744+
}
2745+
if ( !hasAccessorsMetadata ) {
27362746
throw(
27372747
type = "QuickAccessorsMissing",
27382748
message = 'This instance is missing `accessors="true"` in the component metadata. This is required for Quick to work properly. Please add it to your component metadata and reinit your application.'
@@ -2767,7 +2777,8 @@ component accessors="true" {
27672777

27682778
if ( len( meta.originalMetadata.discriminatorValue ) ) {
27692779
try {
2770-
var parentMeta = getComponentMetadata( meta.parentDefinition.meta.fullName );
2780+
var parentMeta = reference.get_Meta().originalMetadata;
2781+
param parentMeta.discriminatorColumn = "";
27712782
meta.parentDefinition[ "discriminatorValue" ] = meta.originalMetadata.discriminatorValue;
27722783
meta.parentDefinition[ "discriminatorColumn" ] = parentMeta.discriminatorColumn;
27732784
} catch ( any e ) {
@@ -2780,20 +2791,13 @@ component accessors="true" {
27802791
}
27812792
}
27822793

2783-
var baseEntityFunctionNames = variables._cache.getOrSet( "quick-metadata:BaseEntity", function() {
2784-
return arrayReduce(
2785-
getComponentMetadata( "quick.models.BaseEntity" ).functions,
2786-
function( acc, func ) {
2787-
arguments.acc[ arguments.func.name ] = "";
2788-
return arguments.acc;
2789-
},
2790-
{}
2791-
);
2792-
} );
2793-
meta[ "functionNames" ] = generateFunctionNameArray(
2794-
from = meta.originalMetadata.functions,
2795-
without = baseEntityFunctionNames
2796-
);
2794+
var functionsForRelationshipDetection = [];
2795+
if ( meta.localMetadata.keyExists( "functions" ) && isArray( meta.localMetadata.functions ) ) {
2796+
functionsForRelationshipDetection = meta.localMetadata.functions;
2797+
} else if ( meta.originalMetadata.keyExists( "functions" ) && isArray( meta.originalMetadata.functions ) ) {
2798+
functionsForRelationshipDetection = meta.originalMetadata.functions;
2799+
}
2800+
meta[ "functionNames" ] = generateFunctionNameArray( from = functionsForRelationshipDetection );
27972801

27982802
param meta.originalMetadata.properties = [];
27992803

@@ -2926,18 +2930,29 @@ component accessors="true" {
29262930
* @return An attribute struct with all the keys needed.
29272931
*/
29282932
private struct function paramAttribute( required struct attr ) {
2929-
param attr.column = arguments.attr.name;
2930-
param attr.persistent = true;
2931-
param attr.nullValue = "";
2932-
param attr.convertToNull = true;
2933-
param attr.casts = "";
2934-
param attr.readOnly = false;
2935-
param attr.sqltype = "";
2936-
param attr.insert = true;
2937-
param attr.update = true;
2938-
param attr.virtual = false;
2939-
param attr.exclude = false;
2940-
param attr.isParentColumn = false;
2933+
if (
2934+
!arguments.attr.keyExists( "persistent" ) &&
2935+
arguments.attr.keyExists( "annotations" ) &&
2936+
isStruct( arguments.attr.annotations ) &&
2937+
arguments.attr.annotations.keyExists( "persistent" )
2938+
) {
2939+
arguments.attr.persistent = arguments.attr.annotations.persistent;
2940+
}
2941+
param attr.column = arguments.attr.name;
2942+
param attr.persistent = true;
2943+
param attr.nullValue = "";
2944+
param attr.convertToNull = true;
2945+
param attr.casts = "";
2946+
param attr.readOnly = false;
2947+
param attr.sqltype = "";
2948+
param attr.insert = true;
2949+
param attr.update = true;
2950+
param attr.virtual = false;
2951+
param attr.exclude = false;
2952+
param attr.isParentColumn = false;
2953+
if ( !isBoolean( attr.persistent ) ) {
2954+
attr.persistent = lCase( trim( attr.persistent & "" ) ) == "true";
2955+
}
29412956
variables._nullValues[ attr.name ] = attr.nullValue;
29422957
return arguments.attr;
29432958
}

tests/specs/integration/BaseEntity/MetadataSpec.cfc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ component extends="tests.resources.ModuleIntegrationSpec" {
9494
.notToHaveKey( "discriminatorColumn" );
9595
} );
9696
} );
97+
98+
describe( "boxlang metadata compatibility", function() {
99+
it(
100+
"can read accessors metadata from annotations",
101+
function() {
102+
expect( function() {
103+
getInstance( "User" );
104+
} ).notToThrow();
105+
},
106+
skip = !server.keyExists( "boxlang" )
107+
);
108+
109+
it(
110+
"can read property persistent metadata from annotations",
111+
function() {
112+
var link = getInstance( "Link" );
113+
expect( link.get_Attributes() ).notToHaveKey( "wirebox" );
114+
},
115+
skip = !server.keyExists( "boxlang" )
116+
);
117+
} );
97118
} );
98119
}
99120

0 commit comments

Comments
 (0)