Files

Class Index [+]

Quicksearch

ActiveRecord::SpawnMethods

Constants

VALID_FIND_OPTIONS

Public Instance Methods

&(r) click to toggle source
Alias for: merge
apply_finder_options(options) click to toggle source
     # File lib/active_record/relation/spawn_methods.rb, line 85
 85:     def apply_finder_options(options)
 86:       relation = clone
 87:       return relation unless options
 88: 
 89:       options.assert_valid_keys(VALID_FIND_OPTIONS)
 90: 
 91:       [:joins, :select, :group, :having, :limit, :offset, :from, :lock].each do |finder|
 92:         if value = options[finder]
 93:           relation = relation.send(finder, value)
 94:         end
 95:       end
 96: 
 97:       relation = relation.readonly(options[:readonly]) if options.key? :readonly
 98: 
 99:       # Give precedence to newly-applied orders and groups to play nicely with with_scope
100:       [:group, :order].each do |finder|
101:         relation.send("#{finder}_values=", Array.wrap(options[finder]) + relation.send("#{finder}_values")) if options.has_key?(finder)
102:       end
103: 
104:       relation = relation.where(options[:conditions]) if options.has_key?(:conditions)
105:       relation = relation.includes(options[:include]) if options.has_key?(:include)
106:       relation = relation.extending(options[:extend]) if options.has_key?(:extend)
107: 
108:       relation
109:     end
except(*skips) click to toggle source
    # File lib/active_record/relation/spawn_methods.rb, line 52
52:     def except(*skips)
53:       result = self.class.new(@klass, table)
54: 
55:       (Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS).each do |method|
56:         result.send(:"#{method}_values=", send(:"#{method}_values")) unless skips.include?(method)
57:       end
58: 
59:       Relation::SINGLE_VALUE_METHODS.each do |method|
60:         result.send(:"#{method}_value=", send(:"#{method}_value")) unless skips.include?(method)
61:       end
62: 
63:       result
64:     end
merge(r) click to toggle source
    # File lib/active_record/relation/spawn_methods.rb, line 5
 5:     def merge(r)
 6:       merged_relation = clone
 7:       return merged_relation unless r
 8: 
 9:       ((Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS) - [:joins, :where]).each do |method|
10:         value = r.send(:"#{method}_values")
11:         unless value.empty?
12:           if method == :includes
13:             merged_relation = merged_relation.includes(value)
14:           else
15:             merged_relation.send(:"#{method}_values=", value)
16:           end
17:         end
18:       end
19: 
20:       merged_relation = merged_relation.joins(r.joins_values)
21: 
22:       merged_wheres = @where_values
23: 
24:       r.where_values.each do |w|
25:         if w.respond_to?(:operator) && w.operator == :==
26:           merged_wheres = merged_wheres.reject { |p|
27:             p.respond_to?(:operator) && p.operator == :== && p.operand1.name == w.operand1.name
28:           }
29:         end
30: 
31:         merged_wheres += [w]
32:       end
33: 
34:       merged_relation.where_values = merged_wheres
35: 
36:       Relation::SINGLE_VALUE_METHODS.reject {|m| m == :lock}.each do |method|
37:         unless (value = r.send(:"#{method}_value")).nil?
38:           merged_relation.send(:"#{method}_value=", value)
39:         end
40:       end
41: 
42:       merged_relation.lock_value = r.lock_value unless merged_relation.lock_value
43: 
44:       # Apply scope extension modules
45:       merged_relation.send :apply_modules, r.extensions
46: 
47:       merged_relation
48:     end
Also aliased as: &
only(*onlies) click to toggle source
    # File lib/active_record/relation/spawn_methods.rb, line 66
66:     def only(*onlies)
67:       result = self.class.new(@klass, table)
68: 
69:       onlies.each do |only|
70:         if (Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS).include?(only)
71:           result.send(:"#{only}_values=", send(:"#{only}_values"))
72:         elsif Relation::SINGLE_VALUE_METHODS.include?(only)
73:           result.send(:"#{only}_value=", send(:"#{only}_value"))
74:         else
75:           raise "Invalid argument : #{only}"
76:         end
77:       end
78: 
79:       result
80:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.