CHANGELOG.md 10.6 KB
Newer Older
1 2 3 4 5 6 7 8
*   Emulate db trigger behaviour for after_commit :destroy, :update

    Race conditions can occur when an ActiveRecord is destroyed
    twice or destroyed and updated. The callbacks should only be
    triggered once, similar to a SQL database trigger.

    *Stefan Budeanu*

9 10 11 12
*   Moved DecimalWithoutScale, Text, and UnsignedInteger from Active Model to Active Record

    *Iain Beeston*

13 14 15 16 17
*   Fix `write_attribute` method to check whether an attribute is aliased or not, and
    use the aliased attribute name if needed.

    *Prathamesh Sonpatki*

18 19 20 21 22 23 24
*   Fix `read_attribute` method to check whether an attribute is aliased or not, and
    use the aliased attribute name if needed.

    Fixes #26417.

    *Prathamesh Sonpatki*

25 26 27 28
*   PostgreSQL & MySQL: Use big integer as primary key type for new tables

    *Jon McCartie*, *Pavel Pravosud*

29 30 31 32 33 34
*   Change the type argument of `ActiveRecord::Base#attribute` to be optional.
    The default is now `ActiveRecord::Type::Value.new`, which provides no type
    casting behavior.

    *Sean Griffin*

35 36 37 38 39 40
*   Fix that unsigned with zerofill is treated as signed.

    Fixes #27125.

    *Ryuta Kamizono*

41 42 43 44
*   Fix the uniqueness validation scope with a polymorphic association.

    *Sergey Alekseev*

45 46 47
*   Raise ActiveRecord::RecordNotFound from collection `*_ids` setters
    for unknown IDs with a better error message.

48 49 50 51
    Changes the collection `*_ids` setters to cast provided IDs the data
    type of the primary key set in the association, not the model
    primary key.

52 53
    *Dominic Cleal*

54 55 56 57 58
*   For PostgreSQL >= 9.4 use `pgcrypto`'s `gen_random_uuid()` instead of
    `uuid-ossp`'s UUID generation function.

    *Yuji Yaginuma*, *Yaw Boakye*

59 60 61 62
*   Introduce `Model#reload_<association>` to bring back the behavior
    of `Article.category(true)` where `category` is a singular
    association.

63 64
    The force reloading of the association reader was deprecated
    in #20888. Unfortunately the suggested alternative of
65 66 67 68 69 70 71 72
    `article.reload.category` does not expose the same behavior.

    This patch adds a reader method with the prefix `reload_` for
    singular associations. This method has the same semantics as
    passing true to the association reader used to have.

    *Yves Senn*

Y
Yves Senn 已提交
73 74 75 76 77
*   Make sure eager loading `ActiveRecord::Associations` also loads
    constants defined in `ActiveRecord::Associations::Preloader`.

    *Yves Senn*

J
Jon Moss 已提交
78 79 80 81 82 83 84
*   Allow `ActionController::Parameters`-like objects to be passed as
    values for Postgres HStore columns.

    Fixes #26904.

    *Jon Moss*

85
*   Added `stat` method to `ActiveRecord::ConnectionAdapters::ConnectionPool`.
86 87 88 89 90 91 92 93

    Example:

        ActiveRecord::Base.connection_pool.stat # =>
        { size: 15, connections: 1, busy: 1, dead: 0, idle: 0, waiting: 0, checkout_timeout: 5 }

    *Pavel Evstigneev*

94 95
*   Avoid `unscope(:order)` when `limit_value` is presented for `count`
    and `exists?`.
96 97

    If `limit_value` is presented, records fetching order is very important
V
Vipul A M 已提交
98
    for performance. We should not unscope the order in the case.
99 100 101

    *Ryuta Kamizono*

V
Vipul A M 已提交
102
*   Fix an Active Record `DateTime` field `NoMethodError` caused by incomplete
103 104 105
    datetime.

    Fixes #24195.
S
Sen-Zhang 已提交
106 107 108

    *Sen Zhang*

V
Vipul A M 已提交
109
*   Allow `slice` to take an array of methods(without the need for splatting).
110 111 112

    *Cohen Carlisle*

113 114 115 116 117 118 119
*   Improved partial writes with HABTM and has many through associations
    to fire database query only if relation has been changed.

    Fixes #19663.

    *Mehmet Emin İNAÇ*

120 121 122 123 124
*   Deprecate passing arguments and block at the same time to
    `ActiveRecord::QueryMethods#select`.

    *Prathamesh Sonpatki*

V
Vipul A M 已提交
125 126
*   Optimistic locking: Added ability to update `locking_column` value.
    Ignore optimistic locking if trying to update with new `locking_column` value.
127 128 129

    *bogdanvlviv*

V
Vipul A M 已提交
130
*   Fixed: Optimistic locking does not work well with `null` in the database.
131 132 133 134 135

    Fixes #26024

    *bogdanvlviv*

136 137 138 139 140
*   Fixed support for case insensitive comparisons of `text` columns in
    PostgreSQL.

    *Edho Arief*

141 142 143 144
*   Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`

    *Trung Duc Tran*

145 146 147 148 149 150 151
*   Return `true` from `update_attribute` when the value of the attribute
    to be updated is unchanged.

    Fixes #26593.

    *Prathamesh Sonpatki*

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
*   Always store errors details information with symbols.

    When the association is autosaved we were storing the details with
    string keys. This was creating inconsistency with other details that are
    added using the `Errors#add` method. It was also inconsistent with the
    `Errors#messages` storage.

    To fix this inconsistency we are always storing with symbols. This will
    cause a small breaking change because in those cases the details could
    be accessed as strings keys but now it can not.

    Fix #26499.

    *Rafael Mendonça França*, *Marcus Vieira*

167 168 169 170 171 172 173
*   Calling `touch` on a model using optimistic locking will now leave the model
    in a non-dirty state with no attribute changes.

    Fixes #26496.

    *Jakob Skjerning*

174 175 176 177 178
*   Using a mysql2 connection after it fails to reconnect will now have an error message
    saying the connection is closed rather than an undefined method error message.

    *Dylan Thacker-Smith*

179 180 181 182 183 184 185
*   PostgreSQL array columns will now respect the encoding of strings contained
    in the array.

    Fixes #26326.

    *Sean Griffin*

186 187 188 189 190 191 192
*   Inverse association instances will now be set before `after_find` or
    `after_initialize` callbacks are run.

    Fixes #26320.

    *Sean Griffin*

193 194 195 196 197
*   Remove unnecessarily association load when a `belongs_to` association has already been
    loaded then the foreign key is changed directly and the record saved.

    *James Coleman*

198
*   Remove standardized column types/arguments spaces in schema dump.
199 200 201

    *Tim Petricola*

202 203 204 205 206 207 208
*   Avoid loading records from database when they are already loaded using
    the `pluck` method on a collection.

    Fixes #25921.

    *Ryuta Kamizono*

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
*   Remove text default treated as an empty string in non-strict mode for
    consistency with other types.

    Strict mode controls how MySQL handles invalid or missing values in
    data-change statements such as INSERT or UPDATE. If strict mode is not
    in effect, MySQL inserts adjusted values for invalid or missing values
    and produces warnings.

        def test_mysql_not_null_defaults_non_strict
          using_strict(false) do
            with_mysql_not_null_table do |klass|
              record = klass.new
              assert_nil record.non_null_integer
              assert_nil record.non_null_string
              assert_nil record.non_null_text
              assert_nil record.non_null_blob

              record.save!
              record.reload

              assert_equal 0,  record.non_null_integer
              assert_equal "", record.non_null_string
              assert_equal "", record.non_null_text
              assert_equal "", record.non_null_blob
            end
          end
        end

    https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

    *Ryuta Kamizono*

241 242 243 244 245 246 247 248
*   Sqlite3 migrations to add a column to an existing table can now be
    successfully rolled back when the column was given and invalid column
    type.

    Fixes #26087

    *Travis O'Neill*

249 250 251 252
*   Deprecate `sanitize_conditions`. Use `sanitize_sql` instead.

    *Ryuta Kamizono*

253 254 255 256 257
*   Doing count on relations that contain LEFT OUTER JOIN Arel node no longer
    force a DISTINCT. This solves issues when using count after a left_joins.

    *Maxime Handfield Lapointe*

258 259 260 261 262
*   RecordNotFound raised by association.find exposes `id`, `primary_key` and
    `model` methods to be consistent with RecordNotFound raised by Record.find.

    *Michel Pigassou*

263 264 265 266 267 268 269
*   Hashes can once again be passed to setters of `composed_of`, if all of the
    mapping methods are methods implemented on `Hash`.

    Fixes #25978.

    *Sean Griffin*

270 271 272 273
*   Fix the SELECT statement in `#table_comment` for MySQL.

    *Takeshi Akima*

274 275 276 277 278
*   Virtual attributes will no longer raise when read on models loaded from the
    database

    *Sean Griffin*

279 280 281 282
*   Support calling the method `merge` in `scope`'s lambda.

    *Yasuhiro Sugino*

283 284 285 286
*   Fixes multi-parameter attributes conversion with invalid params.

    *Hiroyuki Ishii*

287
*   Add newline between each migration in `structure.sql`.
288 289

    Keeps schema migration inserts as a single commit, but allows for easier
290 291 292
    git diffing.

    Fixes #25504.
293 294 295

    *Grey Baker*, *Norberto Lopes*

296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
*   The flag `error_on_ignored_order_or_limit` has been deprecated in favor of
    the current `error_on_ignored_order`.

    *Xavier Noria*

*   Batch processing methods support `limit`:

        Post.limit(10_000).find_each do |post|
          # ...
        end

    It also works in `find_in_batches` and `in_batches`.

    *Xavier Noria*

311
*   Using `group` with an attribute that has a custom type will properly cast
312 313
    the hash keys after calling a calculation method like `count`.

V
Vipul A M 已提交
314
    Fixes #25595.
315 316 317

    *Sean Griffin*

318
*   Fix the generated `#to_param` method to use `omission: ''` so that
319 320 321 322 323 324
    the resulting output is actually up to 20 characters, not
    effectively 17 to leave room for the default "...".
    Also call `#parameterize` before `#truncate` and make the
    `separator: /-/` to maximize the information included in the
    output.

325
    Fixes #23635.
326 327 328

    *Rob Biedenharn*

329 330 331 332 333 334 335
*   Ensure concurrent invocations of the connection reaper cannot allocate the
    same connection to two threads.

    Fixes #25585.

    *Matthew Draper*

336 337 338 339 340 341
*   Inspecting an object with an associated array of over 10 elements no longer
    truncates the array, preventing `inspect` from looping infinitely in some
    cases.

    *Kevin McPhillips*

342
*   Removed the unused methods `ActiveRecord::Base.connection_id` and
343
    `ActiveRecord::Base.connection_id=`.
344 345 346

    *Sean Griffin*

347
*   Ensure hashes can be assigned to attributes created using `composed_of`.
348

349 350 351 352
    Fixes #25210.

    *Sean Griffin*

353 354
*   Fix logging edge case where if an attribute was of the binary type and
    was provided as a Hash.
R
Rafael Mendonça França 已提交
355

356 357
    *Jon Moss*

358 359 360 361
*   Handle JSON deserialization correctly if the column default from database
    adapter returns `''` instead of `nil`.

    *Johannes Opper*
362

363
*   Introduce `ActiveRecord::TransactionSerializationError` for catching
364 365 366 367
    transaction serialization failures or deadlocks.

    *Erol Fornoles*

V
Vipul A M 已提交
368
*   PostgreSQL: Fix `db:structure:load` silent failure on SQL error.
369

370 371
    The command line flag `-v ON_ERROR_STOP=1` should be used
    when invoking `psql` to make sure errors are not suppressed.
372 373 374 375 376 377 378 379 380 381

    Example:

        psql -v ON_ERROR_STOP=1 -q -f awesome-file.sql my-app-db

    Fixes #23818.

    *Ralin Chimev*


382
Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activerecord/CHANGELOG.md) for previous changes.