-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9.x] Add wherehas soft deleting scopes #42100
[9.x] Add wherehas soft deleting scopes #42100
Conversation
Improves relationship constraint merging to consider table aliases.
self::assertCount(0, $versionsT); | ||
|
||
self::assertEquals(1, SoftDeletesTestUser::whereHas('versions')->count()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would match the code style of the rest of the tests (by using $this
over self::
and inline your variables $versionsA
and $versionsT
. More like this:
public function testSelfReferencingRelationshipWithSoftDeletes()
{
[$taylor, $abigail] = $this->createUsers();
$this->assertCount(1, $abigail->versions);
$this->assertTrue($abigail->versions->first()->is($taylor));
$this->assertCount(0, $taylor->versions);
$this->assertEquals(1, SoftDeletesTestUser::whereHas('versions')->count());
}
There also may be a better name than version
for this "test" relationship. Maybe self_referencing()
to make the test relation match the test case, making it more clear?
public function testSelfReferencingRelationshipWithSoftDeletes()
{
[$taylor, $abigail] = $this->createUsers();
$this->assertCount(1, $abigail->self_referencing);
$this->assertTrue($abigail->self_referencing->first()->is($taylor));
$this->assertCount(0, $taylor->self_referencing);
$this->assertEquals(1, SoftDeletesTestUser::whereHas('self_referencing')->count());
}
public function self_referencing()
{
return $this->hasMany(SoftDeletesTestUser::class, 'user_id')->onlyTrashed();
}
Agree and done :) |
An attempt to fix/Improve mergeConstraintsFrom to use correct qualified column names.
Related issue --> #42075