Skip to content

Commit

Permalink
copy values only if it is necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
khiav reoy committed Aug 14, 2021
1 parent 24678ef commit 1aac842
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/rails_or.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def values_to_arel(values)

def spawn_relation(relation, method, condition)
new_relation = relation.klass.send(method, condition)
new_relation.send(ASSIGN_FROM_VALUE, relation.send(FROM_VALUE_METHOD))

from_value = relation.send(FROM_VALUE_METHOD)
new_relation.send(ASSIGN_FROM_VALUE, from_value) if not from_value.empty?

copy_values(new_relation, relation) if IS_RAILS5_FLAG
return new_relation
end
Expand Down Expand Up @@ -47,12 +50,12 @@ def wrap_arel(node)
return Arel::Nodes::Grouping.new(String === node ? Arel.sql(node) : node)
end

def copy_values(to, from) # For Rails 5
to.joins_values = from.joins_values
def copy_values(to, from) # For Rails 5, 6
to.joins_values = from.joins_values if from.joins_values.any?
to.limit_value = from.limit_value
to.group_values = from.group_values
to.group_values = from.group_values if from.group_values.any?
to.distinct_value = from.distinct_value
to.order_values = from.order_values
to.order_values = from.order_values if from.order_values.any?
to.offset_value = from.offset_value
to.references_values = from.references_values
end
Expand Down

0 comments on commit 1aac842

Please sign in to comment.