quick icon indicating copy to clipboard operation
quick copied to clipboard

Virtual attributes not being applied

Open ryanalbrecht opened this issue 6 months ago • 2 comments

I believe there is an issues with virtual attributes not working at all.

When loading an entity, quick will create a new instance of the entity then populate the data and return it. When it creates this new entity the virtual attributes are not persisted.

QuickBuilder.cfc
public any function loadEntity( required struct data ) {
	....
	return getEntity()
		//this is the issue, the virtual attributes from the orginal entity are not persisted
		.newEntity() 
		.assignAttributesData( arguments.data )
		.assignOriginalAttributes( arguments.data )
		.markLoaded();
	....
}

https://github.com/coldbox-modules/quick/blob/4ce7d6d791a733adc82f932883afa2866f1dab97/models/QuickBuilder.cfc#L1327

This is my work around for now

var newEnt = getEntity().newEntity();

// add any virtual attributes present in the original entity to new entity
getEntity()
	.get_virtualAttributes()
	.each( function( item ) {
		newEnt.appendVirtualAttribute( item );
	} );

return newEnt
	.assignAttributesData( arguments.data )
	.assignOriginalAttributes( arguments.data )
	.markLoaded();

ryanalbrecht avatar Aug 16 '24 14:08 ryanalbrecht