Module: ActiveRecord::Collections::Relation

Included in:
ActiveRecord::Collection
Defined in:
lib/active_record/collections/relation.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/active_record/collections/relation.rb', line 4

def self.included(base)
  base.send :extend, ClassMethods
end

Instance Method Details

#allObject



42
43
44
# File 'lib/active_record/collections/relation.rb', line 42

def all
  reset
end

#distinct(bool = true) ⇒ Object



61
62
63
# File 'lib/active_record/collections/relation.rb', line 61

def distinct(bool=true)
  dup.distinct!(bool)
end

#distinct!(bool = true) ⇒ Object



65
66
67
68
69
# File 'lib/active_record/collections/relation.rb', line 65

def distinct!(bool=true)
  #reset!
  @relation = relation.distinct(bool)
  self
end

#includes(*args) ⇒ Object



141
142
143
# File 'lib/active_record/collections/relation.rb', line 141

def includes(*args)
  dup.includes!(*args)
end

#includes!(*args) ⇒ Object



145
146
147
148
149
# File 'lib/active_record/collections/relation.rb', line 145

def includes!(*args)
  #reset!
  relation.includes!(*args)
  self
end

#joins(*args) ⇒ Object



131
132
133
# File 'lib/active_record/collections/relation.rb', line 131

def joins(*args)
  dup.joins!(*args)
end

#joins!(*args) ⇒ Object



135
136
137
138
139
# File 'lib/active_record/collections/relation.rb', line 135

def joins!(*args)
  #reset!
  relation.joins!(*args)
  self
end

#limit(*args, &block) ⇒ Object



111
112
113
# File 'lib/active_record/collections/relation.rb', line 111

def limit(*args, &block)
  dup.limit!(*args, &block)
end

#limit!(*args, &block) ⇒ Object



115
116
117
118
119
# File 'lib/active_record/collections/relation.rb', line 115

def limit!(*args, &block)
  #reset!
  relation.limit!(*args, &block)
  self
end

#loadObject



46
47
48
49
# File 'lib/active_record/collections/relation.rb', line 46

def load
  relation.load
  records
end

#not(*args, &block) ⇒ Object



81
82
83
# File 'lib/active_record/collections/relation.rb', line 81

def not(*args, &block)
  dup.not!(*args, &block)
end

#not!(*args, &block) ⇒ Object



85
86
87
88
89
# File 'lib/active_record/collections/relation.rb', line 85

def not!(*args, &block)
  #reset!
  @relation = relation.where.not(*args, &block)
  self
end

#offset(*args, &block) ⇒ Object



121
122
123
# File 'lib/active_record/collections/relation.rb', line 121

def offset(*args, &block)
  dup.offset!(*args, &block)
end

#offset!(*args, &block) ⇒ Object



125
126
127
128
129
# File 'lib/active_record/collections/relation.rb', line 125

def offset!(*args, &block)
  #reset!
  relation.offset!(*args, &block)
  self
end

#or(*args, &block) ⇒ Object



91
92
93
# File 'lib/active_record/collections/relation.rb', line 91

def or(*args, &block)
  dup.or!(*args, &block)
end

#or!(*args, &block) ⇒ Object



95
96
97
98
99
# File 'lib/active_record/collections/relation.rb', line 95

def or!(*args, &block)
  #reset!
  @relation = relation.or.where(*args, &block)
  self
end

#order(*args, &block) ⇒ Object



101
102
103
# File 'lib/active_record/collections/relation.rb', line 101

def order(*args, &block)
  dup.order!(*args, &block)
end

#order!(*args, &block) ⇒ Object



105
106
107
108
109
# File 'lib/active_record/collections/relation.rb', line 105

def order!(*args, &block)
  #reset!(false)
  relation.order!(*args, &block)
  self
end

#references(*table_names) ⇒ Object



151
152
153
# File 'lib/active_record/collections/relation.rb', line 151

def references(*table_names)
  dup.references!(*table_names)
end

#references!(*table_names) ⇒ Object



155
156
157
158
159
# File 'lib/active_record/collections/relation.rb', line 155

def references!(*table_names)
  #reset!
  relation.references!(*table_names)
  self
end

#reset(clear_total = true, clear_batches = true) ⇒ Object



167
168
169
# File 'lib/active_record/collections/relation.rb', line 167

def reset(clear_total=true, clear_batches=true)
  dup.reset!(clear_total, clear_batches)
end

#reset!(clear_total = true, clear_batches = true) ⇒ Object



171
172
173
174
175
176
177
178
179
180
# File 'lib/active_record/collections/relation.rb', line 171

def reset!(clear_total=true, clear_batches=true)
  @records = @record_ids = @size = nil
  @total_count = nil if clear_total
  relation.reset
  if clear_batches
    @is_batched = false
    relation.limit!(nil).offset!(nil)
  end
  self
end

#select(*args) ⇒ Object



51
52
53
# File 'lib/active_record/collections/relation.rb', line 51

def select(*args)
  dup.select!(*args)
end

#select!(*args) ⇒ Object



55
56
57
58
59
# File 'lib/active_record/collections/relation.rb', line 55

def select!(*args)
  #reset!
  @relation = relation.select(*args)
  self
end

#where(*args, &block) ⇒ Object



71
72
73
# File 'lib/active_record/collections/relation.rb', line 71

def where(*args, &block)
  dup.where!(*args, &block)
end

#where!(*args, &block) ⇒ Object



75
76
77
78
79
# File 'lib/active_record/collections/relation.rb', line 75

def where!(*args, &block)
  #reset!
  relation.where!(*args, &block)
  self
end