Coldfusion Unity Reactor – Default behavior for zero values and nullable columns

I noticed when I was unit testing that when I was setting a reactor record field to zero (userrecord.setUsedFilespace(0)), and then saving the record, the database would not update the table’s value from null to zero.

Turns out, as Chris pointed out, that if a table has a column that allows nulls, any zero value will automatically be saved as NULL. So this column,of type bigint, had no way of getting a zero value into it through reactor, which would always set the zero value to null.

What we did was customize the userDAO. We changed the create and update methods. In the DAO folder of the project, the userDAO was edited. In the create and update methods we changed the code:

null=”#Iif(arguments.to.usedFilespace EQ 0 OR NOT Len(arguments.to.usedFilespace)

TO

null=”#Iif(NOT Len(arguments.to.usedFilespace)

And this allowed the updates and creates to use zero values.

Leave a Reply

Your email address will not be published.