Sha256: 8952f658d03e1a6119608b290ad401adcef0e7a8824e8acd61fe2099bb20ef8b
Contents?: true
Size: 893 Bytes
Versions: 6
Compression:
Stored size: 893 Bytes
Contents
# The QueryAssociationSplitter takes in a query and removes any .includes, and # returns the new query, and an hash of association parts. # # Example: # QueryAssociationSplitter.split([['where', {name: 'Bob'}], ['includes', [:posts, [:posts, :comments], :links]]]) # => ['where', {name: 'Bob'}], {:posts=>{:comments=>{}}, :links=>{}}] module Volt class QueryAssociationSplitter def self.split(query) new_query = [] associations = {} query.each do |method, *args| method = method.to_sym if method == :includes args.flatten(1).each do |path| path = [path].flatten node = associations path.each do |part| node = (node[part] ||= {}) end end else new_query << [method, *args] end end return new_query, associations end end end
Version data entries
6 entries across 6 versions & 1 rubygems