I have this one-to-one relation with two keys (BELEG and POSITION), which works fine in general:
public function Auftragspositionzusatz2()
{
return $this->hasOne('App\Auftragspositionzusatz', 'BELEG', 'BELEG')->where('POSITION', $this->POSITION);
}
However, when queurying this via WHEREHAS, it fails to provide any records:
$belege = Auftragsposition::with('Auftragspositionzusatz2')
->whereHas('Auftragspositionzusatz2', function ($query) {
$query->where('PRODUKTIONWA', '=','1' );
})
->sortable()->paginate(ViewController::itemsPerPage);
In the debug bar I see that at the end it is querying for [POSITION] is null:
select count(*) as aggregate from [HB001AUFTRAGSPOSITION] where cast([DATUMNEUANLAGE] as date) >= '2022-11-01' and exists (select * from [HB001AUFTRAGSPOSITIONZUSATZ] where [HB001AUFTRAGSPOSITION].[BELEG] = [HB001AUFTRAGSPOSITIONZUSATZ].[BELEG] and [PRODUKTIONWA] = '1' and [POSITION] is null)
I do not have this problem, when the model relation is defined by only one key. Is this a known bug? How can I overcome this? Thank you for your help!