diff --git a/models/BaseEntity.cfc b/models/BaseEntity.cfc index c98ffa7e..37bfedf6 100644 --- a/models/BaseEntity.cfc +++ b/models/BaseEntity.cfc @@ -558,7 +558,12 @@ component accessors="true" { */ private void function syncVariablesScopeWithData() { for ( var key in retrieveAttributeNames( withVirtualColumns = false ) ) { - if ( variables.keyExists( key ) && !isReadOnlyAttribute( key ) ) { + var column = retrieveColumnForAlias( key ); + if ( + variables.keyExists( key ) && + !isReadOnlyAttribute( key ) && + ( variables._data.keyExists( column ) || !isNull( variables[ key ] ) ) + ) { assignAttribute( key, variables[ key ] ); } } diff --git a/tests/specs/integration/BaseEntity/MetadataSpec.cfc b/tests/specs/integration/BaseEntity/MetadataSpec.cfc index d5777e17..9ed128bd 100644 --- a/tests/specs/integration/BaseEntity/MetadataSpec.cfc +++ b/tests/specs/integration/BaseEntity/MetadataSpec.cfc @@ -114,6 +114,15 @@ component extends="tests.resources.ModuleIntegrationSpec" { }, skip = !server.keyExists( "boxlang" ) ); + + it( + title = "does not persist uninitialized BoxLang accessor values", + body = function() { + var user = getInstance( "User" ); + expect( user.retrieveAttributesData() ).notToHaveKey( "created_date" ); + }, + skip = !server.keyExists( "boxlang" ) + ); } ); } ); }