Skip to content

Commit

Permalink
Make sure query filter works with database prefix, too
Browse files Browse the repository at this point in the history
  • Loading branch information
franzliedke committed Aug 29, 2015
1 parent cfefc27 commit 98ebc9d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Listeners/PinStickiedDiscussionsToTop.php
Expand Up @@ -39,10 +39,15 @@ public function reorderSearch(DiscussionSearchWillBePerformed $event)
->where('discussions.is_sticky', '=', true)
->where('users_discussions.user_id', '=', $event->search->getActor()->id);
});

// might be quicker to do a subquery in the order clause than a join?
$prefix = app('Illuminate\Database\ConnectionInterface')->getTablePrefix();
array_unshift(
$query->orders,
['type' => 'raw', 'sql' => '(is_sticky AND (users_discussions.read_number IS NULL OR discussions.last_post_number > users_discussions.read_number)) desc']
[
'type' => 'raw',
'sql' => "(is_sticky AND ({$prefix}users_discussions.read_number IS NULL OR {$prefix}discussions.last_post_number > {$prefix}users_discussions.read_number)) desc"
]
);
}
}
Expand Down

0 comments on commit 98ebc9d

Please sign in to comment.