Skip to content

[9.x] Add wherehas soft deleting scopes#42100

Merged
taylorotwell merged 7 commits intolaravel:9.xfrom
tiagof:feature/add-wherehas-soft-deleting-scopes
May 3, 2022
Merged

[9.x] Add wherehas soft deleting scopes#42100
taylorotwell merged 7 commits intolaravel:9.xfrom
tiagof:feature/add-wherehas-soft-deleting-scopes

Conversation

@tiagof
Copy link
Contributor

@tiagof tiagof commented Apr 22, 2022

An attempt to fix/Improve mergeConstraintsFrom to use correct qualified column names.

Related issue --> #42075

self::assertCount(0, $versionsT);

self::assertEquals(1, SoftDeletesTestUser::whereHas('versions')->count());
}
Copy link
Contributor

@BrandonSurowiec BrandonSurowiec Apr 22, 2022

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();
    }

@tiagof
Copy link
Contributor Author

tiagof commented Apr 25, 2022

Agree and done :)

@GrahamCampbell GrahamCampbell changed the title Feature/add wherehas soft deleting scopes [9.x] Add wherehas soft deleting scopes Apr 30, 2022
@taylorotwell taylorotwell merged commit 61b2e98 into laravel:9.x May 3, 2022
@tiagof tiagof deleted the feature/add-wherehas-soft-deleting-scopes branch May 4, 2022 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants