mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Make sure Model#active_relation always adds STI conditions if needed
This commit is contained in:
@@ -872,7 +872,6 @@ module ActiveRecord #:nodoc:
|
|||||||
relation = active_relation
|
relation = active_relation
|
||||||
|
|
||||||
relation = relation.where(conditions) if conditions
|
relation = relation.where(conditions) if conditions
|
||||||
relation = relation.where(type_condition) if finder_needs_type_condition?
|
|
||||||
relation = relation.limit(options[:limit]) if options[:limit].present?
|
relation = relation.limit(options[:limit]) if options[:limit].present?
|
||||||
relation = relation.order(options[:order]) if options[:order].present?
|
relation = relation.order(options[:order]) if options[:order].present?
|
||||||
|
|
||||||
@@ -1389,7 +1388,7 @@ module ActiveRecord #:nodoc:
|
|||||||
def reset_column_information
|
def reset_column_information
|
||||||
undefine_attribute_methods
|
undefine_attribute_methods
|
||||||
@column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
|
@column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
|
||||||
@active_relation = @arel_engine = nil
|
@arel_engine = @active_relation = @arel_engine = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_column_information_and_inheritable_attributes_for_all_subclasses#:nodoc:
|
def reset_column_information_and_inheritable_attributes_for_all_subclasses#:nodoc:
|
||||||
@@ -1504,6 +1503,7 @@ module ActiveRecord #:nodoc:
|
|||||||
|
|
||||||
def active_relation
|
def active_relation
|
||||||
@active_relation ||= Relation.new(self, arel_table)
|
@active_relation ||= Relation.new(self, arel_table)
|
||||||
|
finder_needs_type_condition? ? @active_relation.where(type_condition) : @active_relation
|
||||||
end
|
end
|
||||||
|
|
||||||
def arel_table(table_name_alias = nil)
|
def arel_table(table_name_alias = nil)
|
||||||
@@ -1564,7 +1564,6 @@ module ActiveRecord #:nodoc:
|
|||||||
|
|
||||||
def construct_finder_arel(options = {}, scope = nil)
|
def construct_finder_arel(options = {}, scope = nil)
|
||||||
relation = active_relation.apply_finder_options(options)
|
relation = active_relation.apply_finder_options(options)
|
||||||
relation = relation.where(type_condition) if finder_needs_type_condition?
|
|
||||||
relation = scope.merge(relation) if scope
|
relation = scope.merge(relation) if scope
|
||||||
relation
|
relation
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -167,8 +167,6 @@ module ActiveRecord
|
|||||||
|
|
||||||
if merge_with_relation
|
if merge_with_relation
|
||||||
relation = merge_with_relation.except(:select, :order, :limit, :offset, :group, :from).merge(relation)
|
relation = merge_with_relation.except(:select, :order, :limit, :offset, :group, :from).merge(relation)
|
||||||
else
|
|
||||||
relation = relation.where(type_condition) if finder_needs_type_condition?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
from = merge_with_relation.from_value if merge_with_relation && merge_with_relation.from_value.present?
|
from = merge_with_relation.from_value if merge_with_relation && merge_with_relation.from_value.present?
|
||||||
@@ -194,8 +192,6 @@ module ActiveRecord
|
|||||||
relation.where_values = merge_with_relation.where_values
|
relation.where_values = merge_with_relation.where_values
|
||||||
|
|
||||||
merge_limit = merge_with_relation.taken
|
merge_limit = merge_with_relation.taken
|
||||||
else
|
|
||||||
relation = relation.where(type_condition) if finder_needs_type_condition?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
relation = relation.apply_finder_options(options.slice(:joins, :group, :having, :order, :conditions, :from)).
|
relation = relation.apply_finder_options(options.slice(:joins, :group, :having, :order, :conditions, :from)).
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ module ActiveRecord
|
|||||||
current_scope = current_scoped_methods
|
current_scope = current_scoped_methods
|
||||||
|
|
||||||
unless current_scope
|
unless current_scope
|
||||||
finder_needs_type_condition? ? active_relation.where(type_condition) : active_relation.spawn
|
active_relation.spawn
|
||||||
else
|
else
|
||||||
construct_finder_arel({}, current_scoped_methods)
|
construct_finder_arel({}, current_scoped_methods)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -94,7 +94,9 @@ module ActiveRecord
|
|||||||
def apply_finder_options(options)
|
def apply_finder_options(options)
|
||||||
options.assert_valid_keys(VALID_FIND_OPTIONS)
|
options.assert_valid_keys(VALID_FIND_OPTIONS)
|
||||||
|
|
||||||
relation = joins(options[:joins]).
|
relation = spawn
|
||||||
|
|
||||||
|
relation = relation.joins(options[:joins]).
|
||||||
where(options[:conditions]).
|
where(options[:conditions]).
|
||||||
select(options[:select]).
|
select(options[:select]).
|
||||||
group(options[:group]).
|
group(options[:group]).
|
||||||
|
|||||||
Reference in New Issue
Block a user