Wrong whereHasIn Result
Closed this issue · 2 comments
rizaldywirawan commented
Let's say we have 2 models, Student
and ClassRoom
with relationship Students
hasOne with latestOfMany to ClassRoom
.
public function latestClassRoom(): HasOne
{
return $this->hasOne(Order::class)->latestOfMany();
}
Let's say the records are:
students
table
id | name |
---|---|
1 | Aldy |
class_rooms
table
id | name | student_id |
---|---|---|
1 | A1 | 1 |
2 | A2 | 1 |
3 | A3 | 1 |
4 | A4 | 1 |
When you try:
$students = Student::where('id', 1)->whereHasIn('latestClassRoom', function($query) {
$query->where('name', 'A1');
}->first();
The $students
will still return the Aldy records, but when you try using whereHas, it will return null
.
The right answer is null because the latest classRoom
is not A1, but A1.
biiiiiigmonster commented
Thanks feedback!
Yeah, this is a bug, I will fix it later.
biiiiiigmonster commented
The issue fixed with package v2.2.0, then I will close it.
If you meet others problems, welcome feedback!