[4.2] Check for foreign key with a null value for belongsTo relations...

... to avoid the creation of unnecessary query that obviously returns an empty result. Fixes #4371.
`if (count($keys) === 0)`