diff --git a/src/Api/Actions/Posts/GetsPostsForDiscussion.php b/src/Api/Actions/Posts/GetsPostsForDiscussion.php index f1f847420..f4a096b70 100644 --- a/src/Api/Actions/Posts/GetsPostsForDiscussion.php +++ b/src/Api/Actions/Posts/GetsPostsForDiscussion.php @@ -1,6 +1,5 @@ from('posts') ->where('discussion_id', $discussionId) ->whereNotNull('number') - ->orderByRaw('ABS(CAST(number AS SIGNED) - ?)', [$number]) - ->take(1); + ->take(1) + + // We don't add $number as a binding because for some + // reason doing so makes the bindings go out of order. + ->orderByRaw('ABS(CAST(number AS SIGNED) - '.(int) $number.')') }); return $this->scopeVisibleForUser($query, $user)->count();