Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify calculation scope building. Remove :order from associations …

…as it is troublesome w/ calculation methods using postgresql.
  • Loading branch information...
commit 9e7ec2a9f13aa52cdf07cf9308e8031548dcddc0 1 parent 3c4186b
Pratik lifo authored
15 activerecord/lib/active_record/calculations.rb
View
@@ -164,20 +164,7 @@ def construct_calculation_arel(options = {})
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, includes, construct_join(joins))
construct_finder_arel_with_included_associations(options, join_dependency)
else
- relation = unscoped.apply_finder_options(options.slice(:joins, :conditions, :order, :limit, :offset, :group, :having))
-
- if current_scoped_methods
- relation = current_scoped_methods.except(:select, :order, :limit, :offset, :group, :from).merge(relation)
- end
-
- from = current_scoped_methods.from_value if current_scoped_methods && current_scoped_methods.from_value.present?
- from = options[:from] if from.blank? && options[:from].present?
- relation = relation.from(from)
-
- select = options[:select].presence || (current_scoped_methods ? current_scoped_methods.select_values.join(", ") : nil)
- relation = relation.select(select)
-
- relation
+ scoped.apply_finder_options(options)
end
end
8 activerecord/test/models/company.rb
View
@@ -45,7 +45,7 @@ class Firm < Company
has_many :unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false
has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy
has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all
- has_many :limited_clients, :class_name => "Client", :order => "id", :limit => 1
+ has_many :limited_clients, :class_name => "Client", :limit => 1
has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
has_many :clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}'
has_many :clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id"
@@ -91,10 +91,8 @@ class Firm < Company
end
class DependentFirm < Company
- # added order by id as in fixtures there are two accounts for Rails Core
- # Oracle tests were failing because of that as the second fixture was selected
- has_one :account, :foreign_key => "firm_id", :dependent => :nullify, :order => "id"
- has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
+ has_one :account, :foreign_key => "firm_id", :dependent => :nullify
+ has_many :companies, :foreign_key => 'client_of', :dependent => :nullify
end
class Client < Company
2  activerecord/test/models/post.rb
View
@@ -25,7 +25,7 @@ def greeting
{ :joins => :comments, :conditions => {:comments => {:post_id => post_id} } }
}
- has_many :comments, :order => "body" do
+ has_many :comments do
def find_most_recent
find(:first, :order => "id DESC")
end
Please sign in to comment.
Something went wrong with that request. Please try again.