Skip to content

Commit

Permalink
Merge pull request #637 from pinkary-project/fix/404-after-deleting-user
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Sep 20, 2024
2 parents 98315c7 + 8b9d97d commit b897477
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/Models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,24 @@ public function isSharedUpdate(): bool
return $this->from_id === $this->to_id && $this->content === '__UPDATE__';
}

/**
* @return BelongsTo<Question, Question>
*/
public function root(): BelongsTo
{
return $this->belongsTo(self::class, 'root_id')
->where('is_ignored', false)
->where('is_reported', false);
}

/**
* @return BelongsTo<Question, Question>
*/
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
return $this->belongsTo(self::class, 'parent_id')
->where('is_ignored', false)
->where('is_reported', false);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions app/Queries/Feeds/RecentQuestionsFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function builder(): Builder
})->orderByDesc('updated_at');
}, function (Builder $query): void {
$query->select(DB::Raw('IFNULL(root_id, id) as newest_id'), DB::Raw('IFNULL(root_id, id) as id'))
->where(function (Builder $query): void {
$query->whereNull('root_id')
->orHas('root');
})
->groupBy('newest_id')
->orderByDesc(DB::raw('MAX(`updated_at`)'));
});
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/Models/QuestionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@

$child = $question->children()->with('parent')->first();

$descendant = $question->descendants()->with('root')->first();

expect($question->from)->toBeInstanceOf(User::class)
->and($question->to)->toBeInstanceOf(User::class)
->and($question->likes)->each->toBeInstanceOf(Like::class)
->and($question->hashtags)->each->toBeInstanceOf(Hashtag::class)
->and($question->children)->each->toBeInstanceOf(Question::class)
->and($child->parent)->toBeInstanceOf(Question::class)
->and($descendant->root)->toBeInstanceOf(Question::class)
->and($question->descendants)->each->toBeInstanceOf(Question::class);
});

Expand Down

0 comments on commit b897477

Please sign in to comment.