Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

s/scoped/scope/

  • Loading branch information...
commit b33e7ba140277ade581ed3506144111d29448c9f 1 parent 0e1cafc
@jonleighton jonleighton authored
View
8 activerecord/lib/active_record/associations/association.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/inclusion'
+require 'active_support/deprecation'
module ActiveRecord
module Associations
@@ -81,10 +82,15 @@ def target=(target)
loaded!
end
- def scoped
+ def scope
target_scope.merge(association_scope)
end
+ def scoped
+ ActiveSupport::Deprecation.warn("#scoped is deprecated. use #scope instead.")
+ scope
+ end
+
# The scope for this association.
#
# Note that the association_scope is merged into the target_scope only when the
View
20 activerecord/lib/active_record/associations/collection_association.rb
@@ -50,7 +50,7 @@ def ids_reader
end
else
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
- scoped.pluck(column)
+ scope.pluck(column)
end
end
@@ -71,7 +71,7 @@ def select(select = nil)
if block_given?
load_target.select.each { |e| yield e }
else
- scoped.select(select)
+ scope.select(select)
end
end
@@ -82,7 +82,7 @@ def find(*args)
if options[:finder_sql]
find_by_scan(*args)
else
- scoped.find(*args)
+ scope.find(*args)
end
end
end
@@ -164,9 +164,9 @@ def destroy_all
# Calculate sum using SQL, not Enumerable.
def sum(*args)
if block_given?
- scoped.sum(*args) { |*block_args| yield(*block_args) }
+ scope.sum(*args) { |*block_args| yield(*block_args) }
else
- scoped.sum(*args)
+ scope.sum(*args)
end
end
@@ -189,7 +189,7 @@ def count(column_name = nil, count_options = {})
count_options[:distinct] = true
end
- value = scoped.count(column_name, count_options)
+ value = scope.count(column_name, count_options)
limit = options[:limit]
offset = options[:offset]
@@ -324,7 +324,7 @@ def include?(record)
include_in_memory?(record)
else
load_target if options[:finder_sql]
- loaded? ? target.include?(record) : scoped.exists?(record)
+ loaded? ? target.include?(record) : scope.exists?(record)
end
else
false
@@ -380,7 +380,7 @@ def find_target
if options[:finder_sql]
reflection.klass.find_by_sql(custom_finder_sql)
else
- scoped.to_a
+ scope.to_a
end
records.each { |record| set_inverse_instance(record) }
@@ -440,7 +440,7 @@ def insert_record(record, validate = true, raise = false)
end
def create_scope
- scoped.scope_for_create.stringify_keys
+ scope.scope_for_create.stringify_keys
end
def delete_or_destroy(records, method)
@@ -565,7 +565,7 @@ def find_by_scan(*args)
def first_or_last(type, *args)
args.shift if args.first.is_a?(Hash) && args.first.empty?
- collection = fetch_first_or_last_using_find?(args) ? scoped : load_target
+ collection = fetch_first_or_last_using_find?(args) ? scope : load_target
collection.send(type, *args)
end
end
View
6 activerecord/lib/active_record/associations/collection_proxy.rb
@@ -37,7 +37,7 @@ class CollectionProxy < Relation
def initialize(association) #:nodoc:
@association = association
super association.klass, association.klass.arel_table
- merge! association.scoped
+ merge! association.scope
end
def target
@@ -852,14 +852,14 @@ def proxy_association
# method, which gets the current scope, which is this object, which
# delegates to @association, and so on.
def scoping
- @association.scoped.scoping { yield }
+ @association.scope.scoping { yield }
end
# Returns a <tt>Relation</tt> object for the records in this association
def scope
association = @association
- @association.scoped.extending! do
+ @association.scope.extending! do
define_method(:proxy_association) { association }
end
end
View
6 activerecord/lib/active_record/associations/has_many_association.rb
@@ -38,7 +38,7 @@ def count_records
elsif options[:counter_sql] || options[:finder_sql]
reflection.klass.count_by_sql(custom_counter_sql)
else
- scoped.count
+ scope.count
end
# If there's nothing in the database and @target has no new records
@@ -90,10 +90,10 @@ def delete_records(records, method)
update_counter(-records.length) unless inverse_updates_counter_cache?
else
if records == :all
- scope = scoped
+ scope = self.scope
else
keys = records.map { |r| r[reflection.association_primary_key] }
- scope = scoped.where(reflection.association_primary_key => keys)
+ scope = self.scope.where(reflection.association_primary_key => keys)
end
if method == :delete_all
View
4 activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -126,7 +126,7 @@ def delete_records(records, method)
# even when we just want to delete everything.
records = load_target if records == :all
- scope = through_association.scoped
+ scope = through_association.scope
scope.where! construct_join_attributes(*records)
case method
@@ -171,7 +171,7 @@ def delete_through_records(records)
def find_target
return [] unless target_reflection_has_associated_record?
- scoped.to_a
+ scope.to_a
end
# NOTE - not sure that we can actually cope with inverses here
View
8 activerecord/lib/active_record/associations/preloader/association.rb
@@ -10,7 +10,7 @@ def initialize(klass, owners, reflection, preload_scope)
@reflection = reflection
@preload_scope = preload_scope
@model = owners.first && owners.first.class
- @scoped = nil
+ @scope = nil
@owners_by_key = nil
end
@@ -24,12 +24,12 @@ def preload
raise NotImplementedError
end
- def scoped
- @scoped ||= build_scope
+ def scope
+ @scope ||= build_scope
end
def records_for(ids)
- scoped.where(association_key.in(ids))
+ scope.where(association_key.in(ids))
end
def table
View
4 activerecord/lib/active_record/associations/singular_association.rb
@@ -35,11 +35,11 @@ def build(attributes = {}, options = {})
private
def create_scope
- scoped.scope_for_create.stringify_keys.except(klass.primary_key)
+ scope.scope_for_create.stringify_keys.except(klass.primary_key)
end
def find_target
- scoped.first.tap { |record| set_inverse_instance(record) }
+ scope.first.tap { |record| set_inverse_instance(record) }
end
# Implemented by subclasses
View
2  activerecord/lib/active_record/nested_attributes.rb
@@ -409,7 +409,7 @@ def assign_nested_attributes_for_collection_association(association_name, attrib
association.target
else
attribute_ids = attributes_collection.map {|a| a['id'] || a[:id] }.compact
- attribute_ids.empty? ? [] : association.scoped.where(association.klass.primary_key => attribute_ids)
+ attribute_ids.empty? ? [] : association.scope.where(association.klass.primary_key => attribute_ids)
end
attributes_collection.each do |attributes|
View
2  activerecord/test/cases/associations/has_one_associations_test.rb
@@ -226,7 +226,7 @@ def test_successful_build_association
def test_build_and_create_should_not_happen_within_scope
pirate = pirates(:blackbeard)
- scoped_count = pirate.association(:foo_bulb).scoped.where_values.count
+ scoped_count = pirate.association(:foo_bulb).scope.where_values.count
bulb = pirate.build_foo_bulb
assert_not_equal scoped_count, bulb.scope_after_initialize.where_values.count
Please sign in to comment.
Something went wrong with that request. Please try again.