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



64
65
66
# File 'lib/active_record/collections/relation.rb', line 64

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

#distinct!(bool = true) ⇒ Object



68
69
70
71
# File 'lib/active_record/collections/relation.rb', line 68

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

#group(*args) ⇒ Object



109
110
111
# File 'lib/active_record/collections/relation.rb', line 109

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

#group!(*args) ⇒ Object



113
114
115
116
# File 'lib/active_record/collections/relation.rb', line 113

def group!(*args)
  @relation = relation.group(*args)
  self
end

#includes(*args) ⇒ Object



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

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

#includes!(*args) ⇒ Object



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

def includes!(*args)
  @relation = relation.includes(*args)
  self
end

#joins(*args) ⇒ Object



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

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

#joins!(*args) ⇒ Object



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

def joins!(*args)
  @relation = relation.joins(*args)
  self
end

#limit(*args, &block) ⇒ Object



118
119
120
# File 'lib/active_record/collections/relation.rb', line 118

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

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



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

def limit!(*args, &block)
  @relation = 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

#loaded?Boolean

Returns:

  • (Boolean)


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

def loaded?
  relation.loaded?
end

#not(*args, &block) ⇒ Object



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

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

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



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

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

#offset(*args, &block) ⇒ Object



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

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

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



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

def offset!(*args, &block)
  @relation = 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
# File 'lib/active_record/collections/relation.rb', line 95

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

#order(*args, &block) ⇒ Object



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

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

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



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

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

#references(*table_names) ⇒ Object



154
155
156
# File 'lib/active_record/collections/relation.rb', line 154

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

#references!(*table_names) ⇒ Object



158
159
160
161
# File 'lib/active_record/collections/relation.rb', line 158

def references!(*table_names)
  @relation = relation.references(*table_names)
  self
end

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



169
170
171
# File 'lib/active_record/collections/relation.rb', line 169

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

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



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

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



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

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

#select!(*args) ⇒ Object



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

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

#where(*args, &block) ⇒ Object



73
74
75
# File 'lib/active_record/collections/relation.rb', line 73

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

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



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

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