Skip to content

Commit a057a91

Browse files
authored
fix(Metadata): BoxLang Prime metadata compatibility
1 parent 8ec9a94 commit a057a91

2 files changed

Lines changed: 69 additions & 16 deletions

File tree

models/BaseEntity.cfc

Lines changed: 48 additions & 16 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 ) {
@@ -2790,8 +2801,18 @@ component accessors="true" {
27902801
{}
27912802
);
27922803
} );
2804+
var functionsForRelationshipDetection = [];
2805+
if (
2806+
meta.originalMetadata.keyExists( "functions" ) &&
2807+
isArray( meta.originalMetadata.functions ) &&
2808+
!meta.originalMetadata.functions.isEmpty()
2809+
) {
2810+
functionsForRelationshipDetection = meta.originalMetadata.functions;
2811+
} else if ( meta.localMetadata.keyExists( "functions" ) && isArray( meta.localMetadata.functions ) ) {
2812+
functionsForRelationshipDetection = meta.localMetadata.functions;
2813+
}
27932814
meta[ "functionNames" ] = generateFunctionNameArray(
2794-
from = meta.originalMetadata.functions,
2815+
from = functionsForRelationshipDetection,
27952816
without = baseEntityFunctionNames
27962817
);
27972818

@@ -2926,18 +2947,29 @@ component accessors="true" {
29262947
* @return An attribute struct with all the keys needed.
29272948
*/
29282949
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;
2950+
if (
2951+
!arguments.attr.keyExists( "persistent" ) &&
2952+
arguments.attr.keyExists( "annotations" ) &&
2953+
isStruct( arguments.attr.annotations ) &&
2954+
arguments.attr.annotations.keyExists( "persistent" )
2955+
) {
2956+
arguments.attr.persistent = arguments.attr.annotations.persistent;
2957+
}
2958+
param attr.column = arguments.attr.name;
2959+
param attr.persistent = true;
2960+
param attr.nullValue = "";
2961+
param attr.convertToNull = true;
2962+
param attr.casts = "";
2963+
param attr.readOnly = false;
2964+
param attr.sqltype = "";
2965+
param attr.insert = true;
2966+
param attr.update = true;
2967+
param attr.virtual = false;
2968+
param attr.exclude = false;
2969+
param attr.isParentColumn = false;
2970+
if ( !isBoolean( attr.persistent ) ) {
2971+
attr.persistent = lCase( trim( attr.persistent & "" ) ) == "true";
2972+
}
29412973
variables._nullValues[ attr.name ] = attr.nullValue;
29422974
return arguments.attr;
29432975
}

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+
title = "can read accessors metadata from annotations",
101+
body = function() {
102+
expect( function() {
103+
getInstance( "User" );
104+
} ).notToThrow();
105+
},
106+
skip = !server.keyExists( "boxlang" )
107+
);
108+
109+
it(
110+
title = "can read property persistent metadata from annotations",
111+
body = 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)