Skip to content

Commit

Permalink
Get rid of Model.construct_finder_arel_with_includes. Use construct_f…
Browse files Browse the repository at this point in the history
…inder_arel instead
  • Loading branch information
lifo committed Jan 2, 2010
1 parent a9c790e commit c513471
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def find(*args)
find_scope = construct_scope[:find].slice(:conditions, :order) find_scope = construct_scope[:find].slice(:conditions, :order)


with_scope(:find => find_scope) do with_scope(:find => find_scope) do
relation = @reflection.klass.send(:construct_finder_arel_with_includes, options) relation = @reflection.klass.send(:construct_finder_arel, options)


case args.first case args.first
when :first, :last, :all when :first, :last, :all
Expand Down
21 changes: 8 additions & 13 deletions activerecord/lib/active_record/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ def find(*args)
options = args.extract_options! options = args.extract_options!
set_readonly_option!(options) set_readonly_option!(options)


relation = construct_finder_arel_with_includes(options) relation = construct_finder_arel(options)


case args.first case args.first
when :first, :last, :all when :first, :last, :all
Expand Down Expand Up @@ -1581,17 +1581,7 @@ def construct_finder_arel(options = {}, scope = scope(:find))
offset(construct_offset(options[:offset], scope)). offset(construct_offset(options[:offset], scope)).
from(options[:from]) from(options[:from])


lock = (scope && scope[:lock]) || options[:lock] include_associations = merge_includes(scope && scope[:include], options[:include])
relation = relation.lock if lock.present?

relation = relation.readonly if options[:readonly]

relation
end

def construct_finder_arel_with_includes(options = {})
relation = construct_finder_arel(options)
include_associations = merge_includes(scope(:find, :include), options[:include])


if include_associations.any? if include_associations.any?
if references_eager_loaded_tables?(options) if references_eager_loaded_tables?(options)
Expand All @@ -1601,6 +1591,11 @@ def construct_finder_arel_with_includes(options = {})
end end
end end


lock = (scope && scope[:lock]) || options[:lock]
relation = relation.lock if lock.present?

relation = relation.readonly if options[:readonly]

relation relation
end end


Expand Down Expand Up @@ -1722,7 +1717,7 @@ def method_missing(method_id, *arguments, &block)
super unless all_attributes_exists?(attribute_names) super unless all_attributes_exists?(attribute_names)
if match.finder? if match.finder?
options = arguments.extract_options! options = arguments.extract_options!
relation = options.any? ? construct_finder_arel_with_includes(options) : scoped relation = options.any? ? construct_finder_arel(options) : scoped
relation.send :find_by_attributes, match, attribute_names, *arguments relation.send :find_by_attributes, match, attribute_names, *arguments
elsif match.instantiator? elsif match.instantiator?
scoped.send :find_or_instantiator_by_attributes, match, attribute_names, *arguments, &block scoped.send :find_or_instantiator_by_attributes, match, attribute_names, *arguments, &block
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/named_scope.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def scoped(options = {}, &block)
unless scoped?(:find) unless scoped?(:find)
finder_needs_type_condition? ? active_relation.where(type_condition) : active_relation.spawn finder_needs_type_condition? ? active_relation.where(type_condition) : active_relation.spawn
else else
construct_finder_arel_with_includes construct_finder_arel
end end
end end
end end
Expand Down

0 comments on commit c513471

Please sign in to comment.