Skip to content

Commit

Permalink
Use attr_reader
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikspang authored and glebm committed Oct 14, 2024
1 parent 3cb6e38 commit c853471
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/active_record_union/active_record/relation/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def set_operation(operation, relation_or_where_arg, *args)
other = if args.empty? && relation_or_where_arg.is_a?(Relation)
relation_or_where_arg
else
@klass.where(relation_or_where_arg, *args)
self.klass.where(relation_or_where_arg, *args)
end

verify_relations_for_set_operation!(operation, self, other)
Expand All @@ -37,20 +37,20 @@ def set_operation(operation, relation_or_where_arg, *args)
end

set = SET_OPERATION_TO_AREL_CLASS[operation].new(left, right)
from = Arel::Nodes::TableAlias.new(set, @klass.arel_table.name)
from = Arel::Nodes::TableAlias.new(set, self.klass.arel_table.name)
build_union_relation(from, other)
end

if ActiveRecord.gem_version >= Gem::Version.new('5.2.0.beta2')
# Since Rails 5.2, binds are maintained only in the Arel AST.
def build_union_relation(arel_table_alias, _other)
@klass.unscoped.from(arel_table_alias)
self.klass.unscoped.from(arel_table_alias)
end
elsif ActiveRecord::VERSION::MAJOR >= 5
# In Rails >= 5.0, < 5.2, binds are maintained only in ActiveRecord
# relations and clauses.
def build_union_relation(arel_table_alias, other)
relation = @klass.unscoped.spawn
relation = self.klass.unscoped.spawn
relation.from_clause =
UnionFromClause.new(arel_table_alias, nil,
self.bound_attributes + other.bound_attributes)
Expand All @@ -71,7 +71,7 @@ def binds
# In Rails 4.x, binds are maintained in both ActiveRecord relations and
# clauses and also in their Arel ASTs.
def build_union_relation(arel_table_alias, other)
relation = @klass.unscoped.from(arel_table_alias)
relation = self.klass.unscoped.from(arel_table_alias)
relation.bind_values = self.arel.bind_values + self.bind_values +
other.arel.bind_values + other.bind_values
relation
Expand Down

0 comments on commit c853471

Please sign in to comment.