13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/active_record/collections/serialization.rb', line 13
def from_hash(hash)
hash.symbolize_keys!
collection = new(hash[:klass])
collection.select!(*hash[:select]) unless hash[:select].empty?
collection.distinct! if hash[:distinct] == true
collection.joins!(*hash[:joins]) unless hash[:joins].empty?
collection.references!(*hash[:references]) unless hash[:references].empty?
collection.includes!(*hash[:includes]) unless hash[:includes].empty?
collection.where!(*hash[:bind].map { |b| b[:value] }.unshift(hash[:where].join(" AND ").gsub(/\$\d/,'?'))) unless hash[:where].empty?
collection.group!(hash[:group]) unless hash[:group].empty?
collection.order!(hash[:order]) unless hash[:order].empty?
collection.limit!(hash[:limit]) unless hash[:limit].nil?
collection.offset!(hash[:offset]) unless hash[:offset].nil?
collection
end
|