sebduggan
sebduggan

Reputation: 561

Set NULL values in CF9 ORM

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 ''.

Upvotes: 11

Views: 8573

Answers (2)

Mike Causer
Mike Causer

Reputation: 8324

A trick I learned somewhere along the way.

It's slower to call a ton of JavaCast("null","")'s than it is to call:

// slower
yourEntity.setNumber1( javaCast("null","") );
yourEntity.setNumber2( javaCast("null","") );
yourEntity.setNumber3( javaCast("null","") );

// faster
function getNull() {}
yourEntity.setNumber1( getNull() );
yourEntity.setNumber2( getNull() );
yourEntity.setNumber3( getNull() );

// we're talking microseconds difference, but it sure adds up.

Upvotes: 0

Henry
Henry

Reputation: 32905

Either:

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

or, add a removeNumber method:

function removeNumber()
{
    structDelete(variables,"number");
}

Upvotes: 17

Related Questions