Reputation: 2617
I have a custom validation rule that is checking the DB for NULL.
I need to look for null or empty.
HAVE:
$query = $this->db()->table($table);
...
foreach( $null_columns as $col )
$query->where_null($col);
Which results in something like: SELECT * FROM t WHERE col1=foo AND col2 IS NULL
WANT:
SELECT * FROM t WHERE col1=blah AND (col2 = '' OR col2 IS NULL)
QUESTION:
Is where-nested()
the right tool for the job?
If so, I'd really like to see an example.
If not, what's a good way to approach this?
Upvotes: 1
Views: 93
Reputation: 2617
Well, I ended up getting it to work this way:
$query = $this->db()->table($table);
...
foreach( $null_columns as $col )
{
$query->where(function($q) use($col){
$q->where($col,'=','');
$q->or_where_null($col);
});
}
... but would still like to see an example of using where_nested()
to do this, if possible. I always appreciate learning something new :)
Upvotes: 1