Module: ActiveRecord::Relation::DeprecatedMethods
- Included in:
- ActiveRecord::Relation
- Defined in:
- lib/active_record/deprecated_finders/relation.rb
Constant Summary collapse
- VALID_FIND_OPTIONS =
[ :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :having, :from, :lock ]
Instance Method Summary collapse
- #all(*args) ⇒ Object
-
#apply_finder_options(options, silence_deprecation = false) ⇒ Object
The silence_deprecation arg is for internal use, where we have already output a deprecation further up the call stack.
- #calculate(operation, column_name, options = {}) ⇒ Object
- #find(*args) ⇒ Object
- #find_in_batches(options = {}, &block) ⇒ Object
- #first(*args) ⇒ Object
- #last(*args) ⇒ Object
- #update_all_with_deprecated_options(updates, conditions = nil, options = {}) ⇒ Object
Instance Method Details
#all(*args) ⇒ Object
161 162 163 164 165 166 167 168 169 |
# File 'lib/active_record/deprecated_finders/relation.rb', line 161 def all(*args) ActiveSupport::Deprecation.warn( "Relation#all is deprecated. If you want to eager-load a relation, you can " \ "call #load (e.g. `Post.where(published: true).load`). If you want " \ "to get an array of records from a relation, you can call #to_a (e.g. " \ "`Post.where(published: true).to_a`).", caller ) (args.first, true).to_a end |
#apply_finder_options(options, silence_deprecation = false) ⇒ Object
The silence_deprecation arg is for internal use, where we have already output a deprecation further up the call stack.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/active_record/deprecated_finders/relation.rb', line 12 def (, silence_deprecation = false) ActiveSupport::Deprecation.warn("#apply_finder_options is deprecated") unless silence_deprecation relation = clone return relation unless .assert_valid_keys(VALID_FIND_OPTIONS) finders = .dup finders.delete_if { |key, value| value.nil? && key != :limit } ((VALID_FIND_OPTIONS - [:conditions, :include]) & finders.keys).each do |finder| relation = relation.send(finder, finders[finder]) end relation = relation.where(finders[:conditions]) if .has_key?(:conditions) relation = relation.includes(finders[:include]) if .has_key?(:include) relation end |
#calculate(operation, column_name, options = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/active_record/deprecated_finders/relation.rb', line 74 def calculate(operation, column_name, = {}) if .except(:distinct).present? ActiveSupport::Deprecation.warn( "Relation#calculate with finder options is deprecated. Please build " \ "a scope and then call calculate on it instead.", caller ) (.except(:distinct), true) .calculate(operation, column_name, .slice(:distinct)) else super end end |
#find(*args) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/active_record/deprecated_finders/relation.rb', line 88 def find(*args) = args. if .present? scope = (, true) case finder = args.first when :first, :last, :all ActiveSupport::Deprecation.warn( "Calling #find(#{finder.inspect}) is deprecated. Please call " \ "##{finder} directly instead. You have also used finder options. " \ "These are also deprecated. Please build a scope instead of using " \ "finder options.", caller ) scope.send(finder) else ActiveSupport::Deprecation.warn( "Passing options to #find is deprecated. Please build a scope " \ "and then call #find on it.", caller ) scope.find(*args) end else case finder = args.first when :first, :last, :all ActiveSupport::Deprecation.warn( "Calling #find(#{finder.inspect}) is deprecated. Please call " \ "##{finder} directly instead.", caller ) send(finder) else super end end end |
#find_in_batches(options = {}, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/active_record/deprecated_finders/relation.rb', line 57 def find_in_batches( = {}, &block) if ( = .except(:start, :batch_size)).present? ActiveSupport::Deprecation.warn( "Relation#find_in_batches with finder options is deprecated. Please build " \ "a scope and then call find_in_batches on it instead.", caller ) raise "You can't specify an order, it's forced to be #{batch_order}" if [:order].present? raise "You can't specify a limit, it's forced to be the batch_size" if [:limit].present? (, true). find_in_batches(.slice(:start, :batch_size), &block) else super end end |
#first(*args) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/active_record/deprecated_finders/relation.rb', line 127 def first(*args) if args.empty? super else if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) super else ActiveSupport::Deprecation.warn( "Relation#first with finder options is deprecated. Please build " \ "a scope and then call #first on it instead.", caller ) (args.first, true).first end end end |
#last(*args) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/active_record/deprecated_finders/relation.rb', line 144 def last(*args) if args.empty? super else if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) super else ActiveSupport::Deprecation.warn( "Relation#last with finder options is deprecated. Please build " \ "a scope and then call #last on it instead.", caller ) (args.first, true).last end end end |
#update_all_with_deprecated_options(updates, conditions = nil, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/active_record/deprecated_finders/relation.rb', line 32 def (updates, conditions = nil, = {}) scope = self if conditions scope = where(conditions) ActiveSupport::Deprecation.warn( "Relation#update_all with conditions is deprecated. Please use " \ "Item.where(color: 'red').update_all(...) rather than " \ "Item.update_all(..., color: 'red').", caller ) end if .present? scope = scope.(.slice(:limit, :order), true) ActiveSupport::Deprecation.warn( "Relation#update_all with :limit / :order options is deprecated. " \ "Please use e.g. Post.limit(1).order(:foo).update_all instead.", caller ) end scope.(updates) end |