Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Rails 4.2 patches to better match the code in Rails 4.2 #17

Merged
merged 1 commit into from
Aug 2, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions lib/store_base_sti_class_for_4_2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ def build_scope
scope = klass.unscoped

values = reflection_scope.values
reflection_binds = reflection_scope.bind_values
preload_values = preload_scope.values
preload_binds = preload_scope.bind_values

scope.where_values = Array(values[:where]) + Array(preload_values[:where])
scope.references_values = Array(values[:references]) + Array(preload_values[:references])
scope.bind_values = (reflection_binds + preload_binds)

select_method = scope.respond_to?(:select!) ? :select! : :_select!
scope.send select_method, preload_values[:select] || values[:select] || table[Arel.star]
scope._select! preload_values[:select] || values[:select] || table[Arel.star]
scope.includes! preload_values[:includes] || values[:includes]
scope.joins! preload_values[:joins] || values[:joins]
scope.order! preload_values[:order] || values[:order]

if preload_values.key? :order
scope.order! preload_values[:order]
else
if values.key? :order
scope.order! values[:order]
end
if preload_values[:readonly] || values[:readonly]
scope.readonly!
end

if options[:as]
Expand Down Expand Up @@ -107,10 +107,11 @@ def through_scope
unless reflection_scope.where_values.empty?
scope.includes_values = Array(reflection_scope.values[:includes] || options[:source])
scope.where_values = reflection_scope.values[:where]
scope.bind_values = reflection_scope.bind_values
end

scope.references! reflection_scope.values[:references]
scope.order! reflection_scope.values[:order] if scope.eager_loading?
scope = scope.order reflection_scope.values[:order] if scope.eager_loading?
end

scope
Expand Down Expand Up @@ -141,13 +142,7 @@ def self.get_bind_values(owner, chain)
end
binds
end
class BindSubstitution
def bind_value(scope, column, value, alias_tracker)
substitute = alias_tracker.connection.substitute_at(column)
scope.bind_values += [[column, @block.call(value)]]
substitute
end
end

def next_chain_scope(scope, table, reflection, tracker, assoc_klass, foreign_table, next_reflection)
join_keys = reflection.join_keys(assoc_klass)
key = join_keys.key
Expand Down Expand Up @@ -176,6 +171,7 @@ def next_chain_scope(scope, table, reflection, tracker, assoc_klass, foreign_tab

scope = scope.joins(join(foreign_table, constraint))
end

def last_chain_scope(scope, table, reflection, owner, tracker, assoc_klass)
join_keys = reflection.join_keys(assoc_klass)
key = join_keys.key
Expand Down