From 574f255629a45cd67babcfb9bb8e163e091a53b8 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 14 Dec 2015 08:34:14 -0700 Subject: Use a bind param for `LIMIT` and `OFFSET` We currently generate an unbounded number of prepared statements when `limit` or `offset` are called with a dynamic argument. This changes `LIMIT` and `OFFSET` to use bind params, eliminating the problem. `Type::Value#hash` needed to be implemented, as it turns out we busted the query cache if the type object used wasn't exactly the same object. This drops support for passing an `Arel::Nodes::SqlLiteral` to `limit`. Doing this relied on AR internals, and was never officially supported usage. Fixes #22250. --- activemodel/lib/active_model/type/value.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/type/value.rb b/activemodel/lib/active_model/type/value.rb index 5fea0561a6..9d1f267b41 100644 --- a/activemodel/lib/active_model/type/value.rb +++ b/activemodel/lib/active_model/type/value.rb @@ -90,6 +90,11 @@ module ActiveModel scale == other.scale && limit == other.limit end + alias eql? == + + def hash + [self.class, precision, scale, limit].hash + end def assert_valid_value(*) end -- cgit v1.2.3 From 61e50814040d68c640b16afd2b9c419d2f12fad6 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 3 Dec 2015 21:18:57 +0300 Subject: `ActiveRecord::Base#becomes` should copy the errors --- activemodel/lib/active_model/errors.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 4726a68f69..ef6141a51d 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -81,6 +81,18 @@ module ActiveModel super end + # Copies the errors from other. + # + # other - The ActiveModel::Errors instance. + # + # Examples + # + # person.errors.copy!(other) + def copy!(other) # :nodoc: + @messages = other.messages.dup + @details = other.details.dup + end + # Clear the error messages. # # person.errors.full_messages # => ["name cannot be nil"] -- cgit v1.2.3