CHANGELOG.md 14.8 KB
Newer Older
1 2 3 4 5 6 7
*   Compare deserialized values for `PostgreSQL::OID::Hstore` types when
    calling `ActiveRecord::Dirty#changed_in_place?`

    Fixes #27502.

    *Jon Moss*

8 9 10 11 12
*   Raise `ArgumentError` when passing an `ActiveRecord::Base` instance to `.find`
    and `.exists?`.

    *Rafael Mendonça França*

13 14 15 16 17 18
*   Respect precision option for arrays of timestamps.

    Fixes #27514.

    *Sean Griffin*

19 20 21 22
*   Optimize slow model instantiation when using STI and `store_full_sti_class = false` option.

    *Konstantin Lazarev*

23 24 25 26 27 28 29 30 31 32 33 34 35
*   Add `touch` option to counter cache modifying methods.

    Works when updating, resetting, incrementing and decrementing counters:

        # Touches `updated_at`/`updated_on`.
        Topic.increment_counter(:messages_count, 1, touch: true)
        Topic.decrement_counter(:messages_count, 1, touch: true)

        # Touches `last_discussed_at`.
        Topic.reset_counters(18, :messages, touch: :last_discussed_at)

        # Touches `updated_at` and `last_discussed_at`.
        Topic.update_counters(18, messages_count: 5, touch: %i( updated_at last_discussed_at ))
36 37 38 39 40

    Fixes #26724.

    *Jarred Trost*

41 42 43 44
*   Remove deprecated `#uniq`, `#uniq!`, and `#uniq_value`.

    *Ryuta Kamizono*

45 46 47 48
*   Remove deprecated `#insert_sql`, `#update_sql`, and `#delete_sql`.

    *Ryuta Kamizono*

49 50 51 52
*   Remove deprecated `#use_transactional_fixtures` configuration.

    *Rafael Mendonça França*

53 54 55 56
*   Remove deprecated `#raise_in_transactional_callbacks` configuration.

    *Rafael Mendonça França*

57 58 59 60
*   Remove deprecated `#load_schema_for`.

    *Rafael Mendonça França*

61
*   Remove deprecated conditions parameter from `#destroy_all` and `#delete_all`.
62 63 64

    *Rafael Mendonça França*

65 66 67 68
*   Remove deprecated support to passing arguments to `#select` when a block is provided.

    *Rafael Mendonça França*

69 70 71 72
*   Remove deprecated support to query using commas on LIMIT.

    *Rafael Mendonça França*

73 74 75 76
*   Remove deprecated support to passing a class as a value in a query.

    *Rafael Mendonça França*

77
*   Raise `ActiveRecord::IrreversibleOrderError` when using `last` with an irreversible
78 79 80 81
    order.

    *Rafael Mendonça França*

82
*   Raise when a `has_many :through` association has an ambiguous reflection name.
83 84 85

    *Rafael Mendonça França*

86
*   Raise when `ActiveRecord::Migration` is inherited from directly.
87 88 89

    *Rafael Mendonça França*

90 91 92 93 94
*   Remove deprecated `original_exception` argument in `ActiveRecord::StatementInvalid#initialize`
    and `ActiveRecord::StatementInvalid#original_exception`.

    *Rafael Mendonça França*

K
kenta-s 已提交
95
*   `#tables` and `#table_exists?` return only tables and not views.
96 97 98 99 100

    All the deprecations on those methods were removed.

    *Rafael Mendonça França*

101 102 103 104
*   Remove deprecated `name` argument from `#tables`.

    *Rafael Mendonça França*

105 106 107 108
*   Remove deprecated support to passing a column to `#quote`.

    *Rafael Mendonça França*

109 110
*   Set `:time` as a timezone aware type and remove deprecation when
    `config.active_record.time_zone_aware_types` is not explictly set.
111 112 113

    *Rafael Mendonça França*

114 115 116 117
*   Remove deprecated force reload argument in singular and collection association readers.

    *Rafael Mendonça França*

118 119 120 121 122
*   Remove deprecated `activerecord.errors.messages.restrict_dependent_destroy.one` and
    `activerecord.errors.messages.restrict_dependent_destroy.many` i18n scopes.

    *Rafael Mendonça França*

123 124 125 126 127 128 129
*   Allow passing extra flags to `db:structure:load` and `db:structure:dump`

    Introduces `ActiveRecord::Tasks::DatabaseTasks.structure_(load|dump)_flags` to customize the
    eventual commands run against the database, e.g. mysqldump/pg_dump.

    *Kir Shatrov*

R
Richard Monette 已提交
130 131
*   Notifications see frozen SQL string.

132
    Fixes #23774.
R
Richard Monette 已提交
133 134 135

    *Richard Monette*

136
*   RuntimeErrors are no longer translated to `ActiveRecord::StatementInvalid`.
R
Richard Monette 已提交
137 138 139

    *Richard Monette*

140 141 142 143
*   Change the schema cache format to use YAML instead of Marshal.

    *Kir Shatrov*

144 145 146 147 148 149 150
*   Support index length and order options using both string and symbol
    column names.

    Fixes #27243.

    *Ryuta Kamizono*

151 152 153 154
*   Raise `ActiveRecord::RangeError` when values that executed are out of range.

    *Ryuta Kamizono*

155 156 157 158 159 160
*   Raise `ActiveRecord::NotNullViolation` when a record cannot be inserted
    or updated because it would violate a not null constraint.

    *Ryuta Kamizono*

*   Emulate db trigger behaviour for after_commit :destroy, :update.
161 162 163 164 165 166 167

    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*

168
*   Moved `DecimalWithoutScale`, `Text`, and `UnsignedInteger` from Active Model to Active Record.
169 170 171

    *Iain Beeston*

172 173 174 175 176
*   Fix `write_attribute` method to check whether an attribute is aliased or not, and
    use the aliased attribute name if needed.

    *Prathamesh Sonpatki*

177 178 179 180 181 182 183
*   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*

184
*   PostgreSQL & MySQL: Use big integer as primary key type for new tables.
185 186 187

    *Jon McCartie*, *Pavel Pravosud*

188 189 190 191 192 193
*   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*

194 195 196 197 198 199
*   Fix that unsigned with zerofill is treated as signed.

    Fixes #27125.

    *Ryuta Kamizono*

200 201 202 203
*   Fix the uniqueness validation scope with a polymorphic association.

    *Sergey Alekseev*

204
*   Raise `ActiveRecord::RecordNotFound` from collection `*_ids` setters
205 206
    for unknown IDs with a better error message.

207 208 209 210
    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.

211 212
    *Dominic Cleal*

213 214 215 216 217
*   For PostgreSQL >= 9.4 use `pgcrypto`'s `gen_random_uuid()` instead of
    `uuid-ossp`'s UUID generation function.

    *Yuji Yaginuma*, *Yaw Boakye*

218 219 220 221
*   Introduce `Model#reload_<association>` to bring back the behavior
    of `Article.category(true)` where `category` is a singular
    association.

222 223
    The force reloading of the association reader was deprecated
    in #20888. Unfortunately the suggested alternative of
224 225 226 227 228 229 230 231
    `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 已提交
232 233 234 235 236
*   Make sure eager loading `ActiveRecord::Associations` also loads
    constants defined in `ActiveRecord::Associations::Preloader`.

    *Yves Senn*

J
Jon Moss 已提交
237 238 239 240 241 242 243
*   Allow `ActionController::Parameters`-like objects to be passed as
    values for Postgres HStore columns.

    Fixes #26904.

    *Jon Moss*

244
*   Added `stat` method to `ActiveRecord::ConnectionAdapters::ConnectionPool`.
245 246 247 248 249 250 251 252

    Example:

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

    *Pavel Evstigneev*

253 254
*   Avoid `unscope(:order)` when `limit_value` is presented for `count`
    and `exists?`.
255 256

    If `limit_value` is presented, records fetching order is very important
V
Vipul A M 已提交
257
    for performance. We should not unscope the order in the case.
258 259 260

    *Ryuta Kamizono*

V
Vipul A M 已提交
261
*   Fix an Active Record `DateTime` field `NoMethodError` caused by incomplete
262 263 264
    datetime.

    Fixes #24195.
S
Sen-Zhang 已提交
265 266 267

    *Sen Zhang*

V
Vipul A M 已提交
268
*   Allow `slice` to take an array of methods(without the need for splatting).
269 270 271

    *Cohen Carlisle*

272 273 274 275 276 277 278
*   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Ç*

279 280 281 282 283
*   Deprecate passing arguments and block at the same time to
    `ActiveRecord::QueryMethods#select`.

    *Prathamesh Sonpatki*

V
Vipul A M 已提交
284 285
*   Optimistic locking: Added ability to update `locking_column` value.
    Ignore optimistic locking if trying to update with new `locking_column` value.
286 287 288

    *bogdanvlviv*

V
Vipul A M 已提交
289
*   Fixed: Optimistic locking does not work well with `null` in the database.
290

291
    Fixes #26024.
292 293 294

    *bogdanvlviv*

295 296 297 298 299
*   Fixed support for case insensitive comparisons of `text` columns in
    PostgreSQL.

    *Edho Arief*

300
*   Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`.
301 302 303

    *Trung Duc Tran*

304 305 306 307 308 309 310
*   Return `true` from `update_attribute` when the value of the attribute
    to be updated is unchanged.

    Fixes #26593.

    *Prathamesh Sonpatki*

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
*   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*

326 327 328 329 330 331 332
*   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*

333 334 335 336 337
*   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*

338 339 340 341 342 343 344
*   PostgreSQL array columns will now respect the encoding of strings contained
    in the array.

    Fixes #26326.

    *Sean Griffin*

345 346 347 348 349 350 351
*   Inverse association instances will now be set before `after_find` or
    `after_initialize` callbacks are run.

    Fixes #26320.

    *Sean Griffin*

352 353 354 355 356
*   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*

357
*   Remove standardized column types/arguments spaces in schema dump.
358 359 360

    *Tim Petricola*

361 362 363 364 365 366 367
*   Avoid loading records from database when they are already loaded using
    the `pluck` method on a collection.

    Fixes #25921.

    *Ryuta Kamizono*

368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
*   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*

400 401 402 403
*   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.

404
    Fixes #26087.
405 406 407

    *Travis O'Neill*

408 409 410 411
*   Deprecate `sanitize_conditions`. Use `sanitize_sql` instead.

    *Ryuta Kamizono*

412 413 414 415 416
*   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*

417 418 419 420 421
*   RecordNotFound raised by association.find exposes `id`, `primary_key` and
    `model` methods to be consistent with RecordNotFound raised by Record.find.

    *Michel Pigassou*

422 423 424 425 426 427 428
*   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*

429 430 431 432
*   Fix the SELECT statement in `#table_comment` for MySQL.

    *Takeshi Akima*

433
*   Virtual attributes will no longer raise when read on models loaded from the
434
    database.
435 436 437

    *Sean Griffin*

438 439 440 441
*   Support calling the method `merge` in `scope`'s lambda.

    *Yasuhiro Sugino*

442 443 444 445
*   Fixes multi-parameter attributes conversion with invalid params.

    *Hiroyuki Ishii*

446
*   Add newline between each migration in `structure.sql`.
447 448

    Keeps schema migration inserts as a single commit, but allows for easier
449 450 451
    git diffing.

    Fixes #25504.
452 453 454

    *Grey Baker*, *Norberto Lopes*

455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
*   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*

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

V
Vipul A M 已提交
473
    Fixes #25595.
474 475 476

    *Sean Griffin*

477
*   Fix the generated `#to_param` method to use `omission: ''` so that
478 479 480 481 482 483
    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.

484
    Fixes #23635.
485 486 487

    *Rob Biedenharn*

488 489 490 491 492 493 494
*   Ensure concurrent invocations of the connection reaper cannot allocate the
    same connection to two threads.

    Fixes #25585.

    *Matthew Draper*

495 496 497 498 499 500
*   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*

501
*   Removed the unused methods `ActiveRecord::Base.connection_id` and
502
    `ActiveRecord::Base.connection_id=`.
503 504 505

    *Sean Griffin*

506
*   Ensure hashes can be assigned to attributes created using `composed_of`.
507

508 509 510 511
    Fixes #25210.

    *Sean Griffin*

512 513
*   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 已提交
514

515 516
    *Jon Moss*

517 518 519 520
*   Handle JSON deserialization correctly if the column default from database
    adapter returns `''` instead of `nil`.

    *Johannes Opper*
521

522
*   Introduce `ActiveRecord::TransactionSerializationError` for catching
523 524 525 526
    transaction serialization failures or deadlocks.

    *Erol Fornoles*

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

529 530
    The command line flag `-v ON_ERROR_STOP=1` should be used
    when invoking `psql` to make sure errors are not suppressed.
531 532 533 534 535 536 537 538 539 540

    Example:

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

    Fixes #23818.

    *Ralin Chimev*


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