diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-14 13:36:33 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-16 00:02:46 +0530 |
commit | bed9179aa1496f6d28891cf515af0d7e515ebbab (patch) | |
tree | b0c551489b45f93f66c0d726c55fe000b59803ea /activerecord/lib/active_record/associations | |
parent | 1c30ec23fef2479cd037945e57a74e5c89c9ece1 (diff) | |
download | rails-bed9179aa1496f6d28891cf515af0d7e515ebbab.tar.gz rails-bed9179aa1496f6d28891cf515af0d7e515ebbab.tar.bz2 rails-bed9179aa1496f6d28891cf515af0d7e515ebbab.zip |
Make scopes use relations under the hood
Diffstat (limited to 'activerecord/lib/active_record/associations')
3 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 358db6df1d..64dd5cf629 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -58,11 +58,14 @@ module ActiveRecord find_scope = construct_scope[:find].slice(:conditions, :order) with_scope(:find => find_scope) do - relation = @reflection.klass.send(:construct_finder_arel, options) + relation = @reflection.klass.send(:construct_finder_arel, options, @reflection.klass.send(:current_scoped_methods)) case args.first - when :first, :last, :all + when :first, :last relation.send(args.first) + when :all + records = relation.all + @reflection.options[:uniq] ? uniq(records) : records else relation.find(*args) end @@ -402,7 +405,7 @@ module ActiveRecord end elsif @reflection.klass.scopes.include?(method) @reflection.klass.scopes[method].call(self, *args) - else + else with_scope(construct_scope) do if block_given? @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) } diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 214ce5959a..387b85aacd 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -51,8 +51,6 @@ module ActiveRecord end def construct_find_options!(options) - options[:select] = construct_select(options[:select]) - options[:from] ||= construct_from options[:joins] = construct_joins(options[:joins]) options[:include] = @reflection.source_reflection.options[:include] if options[:include].nil? && @reflection.source_reflection.options[:include] end diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb index 1924156e2a..1001199daa 100644 --- a/activerecord/lib/active_record/associations/through_association_scope.rb +++ b/activerecord/lib/active_record/associations/through_association_scope.rb @@ -6,8 +6,7 @@ module ActiveRecord def construct_scope { :create => construct_owner_attributes(@reflection), - :find => { :from => construct_from, - :conditions => construct_conditions, + :find => { :conditions => construct_conditions, :joins => construct_joins, :include => @reflection.options[:include] || @reflection.source_reflection.options[:include], :select => construct_select, |