Skip to content

Commit

Permalink
Merge whereReactedByWithType method to whereReactedBy (#89)
Browse files Browse the repository at this point in the history
Merge scopeWhereReactedByWithType method with scopeWhereReactedBy
antonkomarev authored Jul 28, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 3e9587c commit 8b0f6a9
Showing 4 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ All notable changes to `laravel-love` will be documented in this file.
- ([#87](https://github.com/cybercog/laravel-love/pull/87)) Resolving default attributes values moved from accessors to Eloquent
- ([#88](https://github.com/cybercog/laravel-love/pull/88)) ReactionType attribute `weight` renamed to `mass`
- ([#88](https://github.com/cybercog/laravel-love/pull/88)) ReactionType method `getWeight` renamed to `getMass`
- ([#89](https://github.com/cybercog/laravel-love/pull/89)) Reactable method `scopeWhereReactedByWithType` merged with `scopeWhereReactedBy`

### Removed

1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
- Find all `isReactedByWithType` method usages and replace it with `isReactedBy`
- Find all `isNotReactedByWithType` method usages and replace it with `isNotReactedBy`
- The `ReactionType` method `getWeight` was renamed to `getMass`. If you're using your own implementation of `ReactionType`, please update the method name.
- Find all `whereReactedByWithType` method usages and replace it with `whereReactedBy`

### Database migration

15 changes: 4 additions & 11 deletions src/Reactable/Models/Traits/Reactable.php
Original file line number Diff line number Diff line change
@@ -80,22 +80,15 @@ public function registerAsLoveReactant(): void
}

public function scopeWhereReactedBy(
Builder $query,
ReacterContract $reacter
): Builder {
return $query->whereHas('loveReactant.reactions', function (Builder $reactionsQuery) use ($reacter) {
$reactionsQuery->where('reacter_id', $reacter->getId());
});
}

public function scopeWhereReactedByWithType(
Builder $query,
ReacterContract $reacter,
ReactionTypeContract $reactionType
?ReactionTypeContract $reactionType = null
): Builder {
return $query->whereHas('loveReactant.reactions', function (Builder $reactionsQuery) use ($reacter, $reactionType) {
$reactionsQuery->where('reacter_id', $reacter->getId());
$reactionsQuery->where('reaction_type_id', $reactionType->getId());
if (!is_null($reactionType)) {
$reactionsQuery->where('reaction_type_id', $reactionType->getId());
}
});
}

8 changes: 4 additions & 4 deletions tests/Unit/Reactable/Models/Traits/ReactableTest.php
Original file line number Diff line number Diff line change
@@ -260,16 +260,16 @@ public function it_can_scope_by_reacter_and_reaction_type(): void
]);

$reactedByReacter1WithReactionType1 = Article::query()
->whereReactedByWithType($reacter1, $reactionType1)
->whereReactedBy($reacter1, $reactionType1)
->get();
$reactedByReacter1WithReactionType2 = Article::query()
->whereReactedByWithType($reacter1, $reactionType2)
->whereReactedBy($reacter1, $reactionType2)
->get();
$reactedByReacter2WithReactionType1 = Article::query()
->whereReactedByWithType($reacter2, $reactionType1)
->whereReactedBy($reacter2, $reactionType1)
->get();
$reactedByReacter2WithReactionType2 = Article::query()
->whereReactedByWithType($reacter2, $reactionType2)
->whereReactedBy($reacter2, $reactionType2)
->get();

$this->assertSame([

0 comments on commit 8b0f6a9

Please sign in to comment.