You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When use whereDoesntHave with nullableMorphs relation. it will not count nullable as dosent have.
Steps To Reproduce
prepare project
create new project with laravel 10/11
create MainTable model by php artisan make:model -m MainTable
add $table->nullableMorphs('relate'); to MainTable migration file
add morphTo relation to MainTable Model file public function relate(){ return $this->morphTo(); }
create Relate1model by php artisan make:model -m Relate1
migrate by php artisan migrate
test by this in php artisan tinker
use App\Models\MainTable;
use App\Models\Relate1;
$r1 = new Relate1();
$r1->save();
$m1 = new MainTable();
$m1->save();
$m2 = new MainTable();
$m2->relate()->associate($r1);
$m2->save();
DB::enableQueryLog();
echo MainTable::has('relate')->count(); // 1
echo MainTable::whereDoesntHave('relate')->count(); // 0 expect 1
var_dump(DB::getQueryLog());
it produce this query
selectcount(*) as aggregate from"main_tables"where (("main_tables"."relate_type"= ? and not exists (select*from"relate1s"where"main_tables"."relate_id"="relate1s"."id")))
but it should be (add "main_tables"."relate_type" is null or
selectcount(*) as aggregate from"main_tables"where ("main_tables"."relate_type" is nullor ("main_tables"."relate_type"= ? and not exists (select*from"relate1s"where"main_tables"."relate_id"="relate1s"."id")))
The text was updated successfully, but these errors were encountered:
We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?
Laravel Version
11.39.1
PHP Version
8.2.12
Database Driver & Version
sqlite / mysql
Description
When use whereDoesntHave with nullableMorphs relation. it will not count nullable as dosent have.
Steps To Reproduce
prepare project
php artisan make:model -m MainTable
$table->nullableMorphs('relate');
to MainTable migration filepublic function relate(){ return $this->morphTo(); }
php artisan make:model -m Relate1
php artisan migrate
test by this in
php artisan tinker
it produce this query
but it should be (add
"main_tables"."relate_type" is null or
The text was updated successfully, but these errors were encountered: