tags:

views:

49

answers:

1

Is there a way to get CF9 ORM to insert NULL Values into the database rather than an empty string?

I've got a numeric field which can be null, but throws an error because it's trying to enter ''.

+3  A: 

Either:

yourEntity.setNumber(javacast("null",""));

or, add a removeNumber method:

function removeNumber()
{
    structDelete(variables,"number");
}
Henry
Thanks Henry,Just need to work out a way to do this automatically rather than explicitly every time...Maybe a pre-update eventhandler?
sebduggan
2 ideas for you. 1.) use global event handler and convert "" to null at preinsert/preupdate 2.) extends a base entity class that has setNull(string propertyName)
Henry
If setting javacast("null,"") in controller doesn't bother you, use that. :)
Henry
I tried it using an eventhandler, but it threw an error. It seems that by the time it calls the preInsert() and preUpdate() methods, it has already checked to see if the datatypes are valid for the database table...
sebduggan