Class: ActsAsOrderedTree::Relation::Base

Inherits:
ActiveRecord::Relation
  • Object
show all
Defined in:
lib/acts_as_ordered_tree/relation/base.rb

Direct Known Subclasses

Preloaded

Constant Summary collapse

EMPTY_SCOPE_METHOD =
ActiveRecord::VERSION::STRING < '4.0.0' ? :scoped : :all

Instance Method Summary collapse

Constructor Details

#initialize(class_or_relation, table = nil) ⇒ Base

Create from existing relation or from class and table


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/acts_as_ordered_tree/relation/base.rb', line 7

def initialize(class_or_relation, table = nil)
  relation = class_or_relation

  if class_or_relation.is_a?(Class)
    relation = class_or_relation.send(EMPTY_SCOPE_METHOD)
    table ||= class_or_relation.arel_table

    super(class_or_relation, table)
  else
    super(class_or_relation.klass, class_or_relation.table)
  end

  # copy instance variables from real relation
  relation.instance_variables.each do |ivar|
    instance_variable_set(ivar, relation.instance_variable_get(ivar))
  end
end