Created
December 16, 2016 20:52
-
-
Save arturopie/7d78cb20c0033c62f7a628e03dab72f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conditions_strings = [] | |
conditions_params = {} | |
unless filters[:comment_text].blank? | |
conditions_strings << "comments.text ILIKE :comment_text" | |
conditions_params[:comment_text] = "%#{filters[:comment_text]}%" | |
end | |
conditions = (conditions_params.empty? ? "" : [conditions_strings.join(" AND "), conditions_params]) | |
joins_list = [] | |
joins_list << {:posts => :comment} if filters[:comment_text].present? | |
posts = Post.where(conditions).joins(joins_list).order("expected_ship_at desc, id desc") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment