Exposed icon indicating copy to clipboard operation
Exposed copied to clipboard

fix: EXPOSED-407 compositeMoney() nullability definition issues

Open bog-walk opened this issue 1 year ago • 0 comments

Defining a composite money column as nullable returns a different type:

// non-nullable column
val money: CompositeMoneyColumn<BigDecimal, CurrencyUnit, MonetaryAmount> = compositeMoney()

// actual nullable column
val nullableMoney: CompositeMoneyColumn<MonetaryAmount?> = compositeMoney().nullable()

// expected nullable column
val money: CompositeMoneyColumn<BigDecimal?, CurrencyUnit?, MonetaryAmount?> = compositeMoney().nullable()

The current setup works as long as the insert value is a composite Money value, as the individual columns will not be able to be resolved.

If the component values (BigDecimal and CurrencyUnit) are inserted individually into the component columns, it will only work for either a non-nullable column or a nullable column with a non-null value. This happens because each component column is correctly nullable, but not the actual composite expression itself, resulting in the error:

Can't set null value to non-nullable CompositeMoneyColumn column

This fix adds an overload so that compositeMoney().nullable() returns the expected type and adds the ability to modify the internal nullable property in BiCompositeColumns.

None of the current tests included inserts/updates that targeted the individual component columns, so this has been included too.

bog-walk avatar Jun 26 '24 04:06 bog-walk