coldbox-modules / quick

A ColdBox ORM Engine
https://quick.ortusbooks.com
MIT License
23 stars 19 forks source link

[Quick 7] Undocumented Breaking change from 6 --> 7 #234

Closed homestar9 closed 1 year ago

homestar9 commented 1 year ago

I discovered a breaking change from Quick 6 that I didn't see covered in the docs that might be worth adding. When dealing with casts when the database has null values. I created a little test using BooleanCast@quick as an example.

If you have your entity set up like this:

component 
    extends="quick.models.BaseEntity"
    accessors="true"
    table="test"
{

    property name="id";
    property name="name" sqltype="varchar";
    property name="active" sqltype="bit" casts="BooleanCast@quick"; // <--- boolean cast

}

Return an entity with a null database value in the active field.

var entity = wirebox.getInstance( "TestEntity" ).find( 1 );
debug( entity.getMemento() );  // testbox debug

Quick 5 will output: image

Quick 6 will output: image

Quick 7 will output: image

The same is true for new (unpersisted) entities as well: Quick 5 and 6: image

Quick 7: image

I don't know what the proper behavior is, but it's a notable difference people upgrading might want to know about. Personally, I preferred the old behavior where a null value was cast to false. Either way, updating to Quick 7 caused many of my tests to fail.

bdw429s commented 1 year ago

This issue has been mentioned on Ortus Solutions Community. There might be relevant details there:

https://community.ortussolutions.com/t/quick-7-undocumented-breaking-change-from-6-to-7/9731/1

elpete commented 1 year ago

This was intentional, and was actually fixed in 7.0.1 as a bug fix. The new behavior is the desired behavior since a NULL value does not necessarily mean false. It could mean not set yet. If you want a default value, you should be able to set default="false" on the property.