From 3c53e512dea03eb0b7d8078365cbb78904fe9ec2 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 25 Feb 2015 15:36:17 +1030 Subject: [PATCH] Fix bug causing wrong index to be returned --- src/Api/Actions/Posts/GetsPostsForDiscussion.php | 1 - src/Core/Repositories/EloquentPostRepository.php | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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();