Module: Sequel::Plugins::EagerEach::DatasetMethods

Defined in:
lib/sequel/plugins/eager_each.rb

Instance Method Summary collapse

Instance Method Details

#all(&block) ⇒ Object

If eager loading, clone the dataset and set a flag to let #each know not to call #all, to avoid the infinite loop.



53
54
55
56
57
58
59
# File 'lib/sequel/plugins/eager_each.rb', line 53

def all(&block)
  if use_eager_all?
    clone(:all_called=>true).all(&block)
  else
    super
  end
end

#columns!Object

Don’t call #all when attempting to load the columns.



33
34
35
36
37
38
39
# File 'lib/sequel/plugins/eager_each.rb', line 33

def columns!
  if use_eager_all?
    clone(:all_called=>true).columns!
  else
    super
  end
end

#each(&block) ⇒ Object

Call #all instead of #each if eager loading, unless #each is being called by #all.



43
44
45
46
47
48
49
# File 'lib/sequel/plugins/eager_each.rb', line 43

def each(&block)
  if use_eager_all?
    all(&block)
  else
    super
  end
end

#single_record!Object

Handle eager loading when calling first and related methods. For eager_graph, this does an additional query after retrieving a single record, because otherwise the associated records won’t get eager loaded correctly.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sequel/plugins/eager_each.rb', line 64

def single_record!
  if use_eager_all?
    obj = clone(:all_called=>true).all.first

    if opts[:eager_graph]
      obj = clone(:all_called=>true).where(obj.qualified_pk_hash).unlimited.all.first
    end

    obj
  else
    super
  end
end