Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rename Model.active_relation to Model.unscoped

  • Loading branch information...
commit cd90dcb1bde5c411a55bcec97597a8fe22b56a5d 1 parent e9a1dbe
@lifo lifo authored
View
4 activerecord/lib/active_record/associations.rb
@@ -1703,7 +1703,7 @@ def select_all_rows(options, join_dependency)
end
def construct_finder_arel_with_included_associations(options, join_dependency)
- relation = active_relation
+ relation = unscoped
for association in join_dependency.join_associations
relation = association.join_relation(relation)
@@ -1754,7 +1754,7 @@ def select_limited_ids_array(options, join_dependency)
end
def construct_finder_sql_for_association_limiting(options, join_dependency)
- relation = active_relation
+ relation = unscoped
for association in join_dependency.join_associations
relation = association.join_relation(relation)
View
24 activerecord/lib/active_record/base.rb
@@ -869,7 +869,7 @@ def destroy(id)
# # Update all books that match our conditions, but limit it to 5 ordered by date
# Book.update_all "author = 'David'", "title LIKE '%Rails%'", :order => 'created_at', :limit => 5
def update_all(updates, conditions = nil, options = {})
- relation = active_relation
+ relation = unscoped
relation = relation.where(conditions) if conditions
relation = relation.limit(options[:limit]) if options[:limit].present?
@@ -1388,7 +1388,7 @@ def column_methods_hash #:nodoc:
def reset_column_information
undefine_attribute_methods
@column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
- @arel_engine = @active_relation = nil
+ @arel_engine = @unscoped = nil
end
def reset_column_information_and_inheritable_attributes_for_all_subclasses#:nodoc:
@@ -1501,9 +1501,9 @@ def merge_conditions(*conditions)
"(#{segments.join(') AND (')})" unless segments.empty?
end
- def active_relation
- @active_relation ||= Relation.new(self, arel_table)
- finder_needs_type_condition? ? @active_relation.where(type_condition) : @active_relation
+ def unscoped
+ @unscoped ||= Relation.new(self, arel_table)
+ finder_needs_type_condition? ? @unscoped.where(type_condition) : @unscoped
end
def arel_table(table_name_alias = nil)
@@ -1563,7 +1563,7 @@ def type_name_with_module(type_name)
end
def construct_finder_arel(options = {}, scope = nil)
- relation = active_relation.apply_finder_options(options)
+ relation = unscoped.apply_finder_options(options)
relation = scope.merge(relation) if scope
relation
end
@@ -1585,7 +1585,7 @@ def construct_join(joins)
def build_association_joins(joins)
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, joins, nil)
- relation = active_relation.table
+ relation = unscoped.table
join_dependency.join_associations.map { |association|
if (association_relation = association.relation).is_a?(Array)
[Arel::InnerJoin.new(relation, association_relation.first, *association.association_join.first).joins(relation),
@@ -2193,7 +2193,7 @@ def delete
# be made (since they can't be persisted).
def destroy
unless new_record?
- self.class.active_relation.where(self.class.active_relation[self.class.primary_key].eq(id)).delete_all
+ self.class.unscoped.where(self.class.unscoped[self.class.primary_key].eq(id)).delete_all
end
@destroyed = true
@@ -2480,7 +2480,7 @@ def create_or_update
def update(attribute_names = @attributes.keys)
attributes_with_values = arel_attributes_values(false, false, attribute_names)
return 0 if attributes_with_values.empty?
- self.class.active_relation.where(self.class.active_relation[self.class.primary_key].eq(id)).update(attributes_with_values)
+ self.class.unscoped.where(self.class.unscoped[self.class.primary_key].eq(id)).update(attributes_with_values)
end
# Creates a record with values matching those of the instance attributes
@@ -2493,9 +2493,9 @@ def create
attributes_values = arel_attributes_values
new_id = if attributes_values.empty?
- self.class.active_relation.insert connection.empty_insert_statement_value
+ self.class.unscoped.insert connection.empty_insert_statement_value
else
- self.class.active_relation.insert attributes_values
+ self.class.unscoped.insert attributes_values
end
self.id ||= new_id
@@ -2590,7 +2590,7 @@ def arel_attributes_values(include_primary_key = true, include_readonly_attribut
if value && ((self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time))) || value.is_a?(Hash) || value.is_a?(Array))
value = value.to_yaml
end
- attrs[self.class.active_relation[name]] = value
+ attrs[self.class.unscoped[name]] = value
end
end
end
View
4 activerecord/lib/active_record/calculations.rb
@@ -164,7 +164,7 @@ def construct_calculation_arel(options = {}, merge_with_relation = nil)
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, includes, construct_join(joins))
construct_calculation_arel_with_included_associations(options, join_dependency, merge_with_relation)
else
- relation = active_relation.apply_finder_options(options.slice(:joins, :conditions, :order, :limit, :offset, :group, :having))
+ relation = unscoped.apply_finder_options(options.slice(:joins, :conditions, :order, :limit, :offset, :group, :having))
if merge_with_relation
relation = merge_with_relation.except(:select, :order, :limit, :offset, :group, :from).merge(relation)
@@ -182,7 +182,7 @@ def construct_calculation_arel(options = {}, merge_with_relation = nil)
end
def construct_calculation_arel_with_included_associations(options, join_dependency, merge_with_relation = nil)
- relation = active_relation
+ relation = unscoped
for association in join_dependency.join_associations
relation = association.join_relation(relation)
View
2  activerecord/lib/active_record/locking/optimistic.rb
@@ -78,7 +78,7 @@ def update_with_lock(attribute_names = @attributes.keys) #:nodoc:
attribute_names.uniq!
begin
- relation = self.class.active_relation
+ relation = self.class.unscoped
affected_rows = relation.where(
relation[self.class.primary_key].eq(quoted_id).and(
View
2  activerecord/lib/active_record/named_scope.rb
@@ -29,7 +29,7 @@ def scoped(options = {}, &block)
current_scope = current_scoped_methods
unless current_scope
- active_relation.spawn
+ unscoped.spawn
else
construct_finder_arel({}, current_scoped_methods)
end
View
4 activerecord/lib/active_record/relation/calculation_methods.rb
@@ -53,7 +53,7 @@ def calculate(operation, column_name, options = {})
def execute_simple_calculation(operation, column_name, distinct) #:nodoc:
column = if @klass.column_names.include?(column_name.to_s)
- Arel::Attribute.new(@klass.active_relation, column_name)
+ Arel::Attribute.new(@klass.unscoped, column_name)
else
Arel::SqlLiteral.new(column_name == :all ? "*" : column_name.to_s)
end
@@ -77,7 +77,7 @@ def execute_grouped_calculation(operation, column_name) #:nodoc:
select_statement = if operation == 'count' && column_name == :all
"COUNT(*) AS count_all"
else
- Arel::Attribute.new(@klass.active_relation, column_name).send(operation).as(aggregate_alias).to_sql
+ Arel::Attribute.new(@klass.unscoped, column_name).send(operation).as(aggregate_alias).to_sql
end
select_statement << ", #{group_field} AS #{group_alias}"
View
2  activerecord/lib/active_record/validations/uniqueness.rb
@@ -12,7 +12,7 @@ def setup(klass)
def validate_each(record, attribute, value)
finder_class = find_finder_class_for(record)
- table = finder_class.active_relation
+ table = finder_class.unscoped
table_name = record.class.quoted_table_name
sql, params = mount_sql_and_params(finder_class, table_name, attribute, value)
Please sign in to comment.
Something went wrong with that request. Please try again.