Skip to content

Commit

Permalink
cleanup order code
Browse files Browse the repository at this point in the history
  • Loading branch information
scambra committed Mar 6, 2012
1 parent dd0c412 commit a778bdb
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/active_scaffold/finder.rb
Expand Up @@ -265,7 +265,7 @@ def finder_options(options = {})
full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes)

# create a general-use options array that's compatible with Rails finders
finder_options = { :order => options[:sorting].try(:clause),
finder_options = { :reorder => options[:sorting].try(:clause),
:where => search_conditions,
:joins => joins_for_finder,
:includes => full_includes}
Expand All @@ -278,7 +278,7 @@ def finder_options(options = {})
# See finder_options for valid options
def count_options(find_options = {}, count_includes = nil)
count_includes ||= find_options[:includes] unless find_options[:where].nil?
options = find_options.reject{|k,v| [:select, :order].include? k}
options = find_options.reject{|k,v| [:select, :reorder].include? k}
options[:includes] = count_includes
options
end
Expand Down Expand Up @@ -320,14 +320,8 @@ def find_page(options = {})
end

def append_to_query(query, options)
options.assert_valid_keys :where, :select, :group, :order, :limit, :offset, :joins, :includes, :lock, :readonly, :from
options.assert_valid_keys :where, :select, :group, :reorder, :limit, :offset, :joins, :includes, :lock, :readonly, :from
options.reject{|k, v| v.blank?}.inject(query) do |query, (k, v)|
# default ordering of model has a higher priority than current queries ordering
# fix this by removing existing ordering from arel
if k.to_sym == :order
query = query.where('1=1') unless query.is_a?(ActiveRecord::Relation)
query = query.except(:order)
end
query.send((k.to_sym), v)
end
end
Expand Down

0 comments on commit a778bdb

Please sign in to comment.