Handling null and undefined values in where conditions
Default Behavior
// Both queries will throw an error
const posts1 = await repository.find({
where: {
text: null,
},
})
// Error: Null value encountered in property 'text' of a where condition.
const posts2 = await repository.find({
where: {
text: undefined,
},
})
// Error: Undefined value encountered in property 'text' of a where condition.Configuration
Null Behavior Options
'ignore'
'sql-null'
'throw' (default)
Undefined Behavior Options
'ignore'
'throw' (default)
Using Both Options Together
Supported operations
Find Operations
Repository and EntityManager Methods
Only plain-object criteria is normalized
QueryBuilder with setFindOptions
Not affected: QueryBuilder .where()
How null and undefined behave in QueryBuilder .where()
null in QueryBuilder .where()
undefined in QueryBuilder .where()
Summary table
Last updated