impossible where generated why?

I’ve got the following line of code:

$usage_ids = [];

foreach (Billing::find()->where([$type2 => $id2])->andWhere(['between','date',$date_start, $date_end])->all() as $billing) {

    if ($billing->invoice == null || $billing->invoice->sent_at == null) {

        $usage_ids[] = $billing->usage_id;



I can see in the profiler toolbar that the following query is generated by the if… line:

SELECT * FROM invoice WHERE 0=1

Why is that and can this be improved? I’m hammering the sql server with useless queries this way.

Found the problem: instead of comparing invoice == null, should be invoice_id == null