CHANGELOG.md 14.2 KB
Newer Older
1 2 3 4 5 6 7 8 9
*   `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and 
    strings in column names as equal.
    
    This fixes a rare case in which more bind values are passed than there are
    placeholders for them in the generated SQL statement, which can make PostgreSQL
    throw a `StatementInvalid` exception.
    
    *Nat Budin*

10 11 12 13 14 15
*   `change_column_default` allows `[]` as argument to `change_column_default`.

    Fixes #11586.

    *Yves Senn*

16 17 18 19 20 21 22 23 24
*   Handle `name` and `"char"` column types in the PostgreSQL adapter.

    `name` and `"char"` are special character types used internally by
    PostgreSQL and are used by internal system catalogs. These field types
    can sometimes show up in structure-sniffing queries that feature internal system
    structures or with certain PostgreSQL extensions.

    *J Smith*, *Yves Senn*

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
*   Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and
    NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`

    Example:

        # Before
        Point.create(value: 1.0/0)
        Point.last.value # => 0.0

        # After
        Point.create(value: 1.0/0)
        Point.last.value # => Infinity

    *Innokenty Mikhailov*

40 41 42 43 44 45
*   Allow the PostgreSQL adapter to handle bigserial pk types again.

    Fixes #10410.

    *Patrick Robertson*

46 47 48 49 50 51 52 53 54
*   Deprecate joining, eager loading and preloading of instance dependent
    associations without replacement. These operations happen before instances
    are created. The current behavior is unexpected and can result in broken
    behavior.

    Fixes #15024.

    *Yves Senn*

55 56 57 58 59 60 61 62 63
*   Fixed HABTM's CollectionAssociation size calculation.

    HABTM should fall back to using the normal CollectionAssociation's size
    calculation if the collection is not cached or loaded.

    Fixes #14913 and #14914.

    *Fred Wu*

64 65 66 67 68
*   Return a non zero status when running `rake db:migrate:status` and migration table does
    not exist.

    *Paul B.*

69 70 71 72 73 74 75
*   Add support for module-level `table_name_suffix` in models.

    This makes `table_name_suffix` work the same way as `table_name_prefix` when
    using namespaced models.

    *Jenner LaFave*

76
*   Revert the behaviour of `ActiveRecord::Relation#join` changed through 4.0 => 4.1 to 4.0.
77

78 79
    In 4.1.0 `Relation#join` is delegated to `Arel#SelectManager`.
    In 4.0 series it is delegated to `Array#join`.
80 81 82

    *Bogdan Gusiev*

83 84 85 86 87 88 89 90 91 92 93 94
*   Log nil binary column values correctly.

    When an object with a binary column is updated with a nil value
    in that column, the SQL logger would throw an exception when trying
    to log that nil value. This only occurs when updating a record
    that already has a non-nil value in that column since an initial nil
    value isn't included in the SQL anyway (at least, when dirty checking
    is enabled.) The column's new value will now be logged as `<NULL binary data>`
    to parallel the existing `<N bytes of binary data>` for non-nil values.

    *James Coleman*

95
*   Rails will now pass a custom validation context through to autosave associations
96 97 98 99 100 101
    in order to validate child associations with the same context.

    Fixes #13854.

    *Eric Chahin*, *Aaron Nelson*, *Kevin Casey*

102
*   Stringify all variable keys of mysql connection configuration.
103

104 105
    When the `sql_mode` variable for mysql adapters is set in the configuration
    as a `String`, it was ignored and overwritten by the strict mode option.
106

107
    Fixes #14895.
108 109 110

    *Paul Nikitochkin*

111 112
*   Ensure SQLite3 statements are closed on errors.

113
    Fixes #13631.
114

115
    *Timur Alperovich*
116

117
*   Give ActiveRecord::PredicateBuilder private methods the privacy they deserve.
118 119 120

    *Hector Satre*

121 122 123 124 125 126 127 128
*   When using a custom `join_table` name on a `habtm`, rails was not saving it
    on Reflections. This causes a problem when rails loads fixtures, because it
    uses the reflections to set database with fixtures.

    Fixes #14845.

    *Kassio Borges*

129 130 131 132 133
*   Reset the cache when modifying a Relation with cached Arel.
    Additionally display a warning message to make the user aware.

    *Yves Senn*

134 135 136 137 138 139 140 141 142 143 144 145 146 147
*   PostgreSQL should internally use `:datetime` consistently for TimeStamp. Assures
    different spellings of timestamps are treated the same.

    Example:

        mytimestamp.simplified_type('timestamp without time zone')
        # => :datetime
        mytimestamp.simplified_type('timestamp(6) without time zone')
        # => also :datetime (previously would be :timestamp)

    See #14513.

    *Jefferson Lai*

148 149 150 151 152 153
*   `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.

    Fixes #14841.

    *Lucas Mazza*

154 155 156 157 158 159
*   Fix name collision with `Array#select!` with `Relation#select!`.

    Fixes #14752.

    *Earl St Sauver*

160 161 162 163 164 165 166 167 168
*   Fixed unexpected behavior for `has_many :through` associations going through a scoped `has_many`.

    If a `has_many` association is adjusted using a scope, and another `has_many :through`
    uses this association, then the scope adjustment is unexpectedly neglected.

    Fixes #14537.

    *Jan Habermann*

169 170 171 172
*   `@destroyed` should always be set to `false` when an object is duped.

    *Kuldeep Aggarwal*

173 174 175 176 177 178
*   Fixed has_many association to make it support irregular inflections.

    Fixes #8928.

    *arthurnn*, *Javier Goizueta*

179 180 181 182 183 184
*   Fixed a problem where count used with a grouping was not returning a Hash.

    Fixes #14721.

    *Eric Chahin*

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
*   `sanitize_sql_like` helper method to escape a string for safe use in a SQL
    LIKE statement.

    Example:

        class Article
          def self.search(term)
            where("title LIKE ?", sanitize_sql_like(term))
          end
        end

        Article.search("20% _reduction_")
        # => Query looks like "... title LIKE '20\% \_reduction\_' ..."

    *Rob Gilson*, *Yves Senn*

201 202 203 204 205 206
*   Do not quote uuid default value on `change_column`.

    Fixes #14604.

    *Eric Chahin*

207 208 209 210 211 212 213 214 215 216 217 218 219
*   The comparison between `Relation` and `CollectionProxy` should be consistent.

    Example:

        author.posts == Post.where(author_id: author.id)
        # => true
        Post.where(author_id: author.id) == author.posts
        # => true

    Fixes #13506.

    *Lauro Caetano*

220 221 222 223 224 225 226 227 228 229 230 231 232 233
*   Calling `delete_all` on an unloaded `CollectionProxy` no longer
    generates a SQL statement containing each id of the collection:

    Before:

        DELETE FROM `model` WHERE `model`.`parent_id` = 1
        AND `model`.`id` IN (1, 2, 3...)

    After:

        DELETE FROM `model` WHERE `model`.`parent_id` = 1

    *Eileen M. Uchitelle*, *Aaron Patterson*

234 235 236 237 238 239 240
*   Fixed error for aggregate methods (`empty?`, `any?`, `count`) with `select`
    which created invalid SQL.

    Fixes #13648.

    *Simon Woker*

241 242 243 244 245 246
*   PostgreSQL adapter only warns once for every missing OID per connection.

    Fixes #14275.

    *Matthew Draper*, *Yves Senn*

247 248 249 250 251 252 253
*   PostgreSQL adapter automatically reloads it's type map when encountering
    unknown OIDs.

    Fixes #14678.

    *Matthew Draper*, *Yves Senn*

254
*   Fix insertion of records via `has_many :through` association with scope.
255

256
    Fixes #3548.
257 258 259

    *Ivan Antropov*

260 261 262 263 264 265
*   Auto-generate stable fixture UUIDs on PostgreSQL.

    Fixes: #11524

    *Roderick van Domburg*

E
Evan Whalen 已提交
266 267 268 269 270 271 272
*   Fixed a problem where an enum would overwrite values of another enum
    with the same name in an unrelated class.

    Fixes #14607.

    *Evan Whalen*

273 274 275 276 277 278
*   PostgreSQL and SQLite string columns no longer have a default limit of 255.

    Fixes #13435, #9153.

    *Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn*

279 280 281 282 283 284
*   Make possible to have an association called `records`.

    Fixes #11645.

    *prathamesh-sonpatki*

285 286 287 288 289 290 291 292 293
*   `to_sql` on an association now matches the query that is actually executed, where it
    could previously have incorrectly accrued additional conditions (e.g. as a result of
    a previous query). CollectionProxy now always defers to the association scope's
    `arel` method so the (incorrect) inherited one should be entirely concealed.

    Fixes #14003.

    *Jefferson Lai*

294 295 296 297 298 299 300 301
*   Block a few default Class methods as scope name.

    For instance, this will raise:

        scope :public, -> { where(status: 1) }

    *arthurnn*

302 303 304 305 306 307
*   Fixed error when using `with_options` with lambda.

    Fixes #9805.

    *Lauro Caetano*

308
*   Switch `sqlite3:///` URLs (which were temporarily
309 310 311 312 313 314 315
    deprecated in 4.1) from relative to absolute.

    If you still want the previous interpretation, you should replace
    `sqlite3:///my/path` with `sqlite3:my/path`.

    *Matthew Draper*

D
Dmitry Lavrov 已提交
316 317 318 319 320 321 322 323
*   Treat blank UUID values as `nil`.

    Example:

        Sample.new(uuid_field: '') #=> <Sample id: nil, uuid_field: nil>

    *Dmitry Lavrov*

324 325 326 327
*   Enable support for materialized views on PostgreSQL >= 9.3.

    *Dave Lee*

328 329 330 331
*   The PostgreSQL adapter supports custom domains. Fixes #14305.

    *Yves Senn*

332 333 334 335 336 337 338 339
*   PostgreSQL `Column#type` is now determined through the corresponding OID.
    The column types stay the same except for enum columns. They no longer have
    `nil` as type but `enum`.

    See #7814.

    *Yves Senn*

340 341 342 343 344 345
*   Fixed error when specifying a non-empty default value on a PostgreSQL array column.

    Fixes #10613.

    *Luke Steensen*

346 347 348 349
*   Make possible to change `record_timestamps` inside Callbacks.

    *Tieg Zaharia*

350 351 352 353 354 355 356
*   Fixed error where .persisted? throws SystemStackError for an unsaved model with a
    custom primary key that didn't save due to validation error.

    Fixes #14393.

    *Chris Finne*

357 358 359 360 361 362
*   Introduce `validate` as an alias for `valid?`.

    This is more intuitive when you want to run validations but don't care about the return value.

    *Henrik Nyh*

363
*   Create indexes inline in CREATE TABLE for MySQL.
364 365 366

    This is important, because adding an index on a temporary table after it has been created
    would commit the transaction.
367 368 369

    It also allows creating and dropping indexed tables with fewer queries and fewer permissions
    required.
370 371 372 373 374 375 376 377

    Example:

        create_table :temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query" do |t|
          t.index :zip
        end
        # => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query

378
    *Cody Cutrer*, *Steve Rice*, *Rafael Mendonça Franca*
379

380 381 382 383 384 385
*   Save `has_one` association even if the record doesn't changed.

    Fixes #14407.

    *Rafael Mendonça França*

Y
Yves Senn 已提交
386 387
*   Use singular table name in generated migrations when
    `ActiveRecord::Base.pluralize_table_names` is `false`.
388 389 390 391 392

    Fixes #13426.

    *Kuldeep Aggarwal*

393
*   `touch` accepts many attributes to be touched at once.
394 395 396

    Example:

397 398
        # touches :signed_at, :sealed_at, and :updated_at/on attributes.
        Photo.last.touch(:signed_at, :sealed_at)
399

400 401
    *James Pinto*

402 403 404 405 406 407 408
*   `rake db:structure:dump` only dumps schema information if the schema
    migration table exists.

    Fixes #14217.

    *Yves Senn*

409 410 411 412 413 414 415 416
*   Reap connections that were checked out by now-dead threads, instead
    of waiting until they disconnect by themselves. Before this change,
    a suitably constructed series of short-lived threads could starve
    the connection pool, without ever having more than a couple alive at
    the same time.

    *Matthew Draper*

417 418 419 420 421
*   `pk_and_sequence_for` now ensures that only the pg_depend entries
    pointing to pg_class, and thus only sequence objects, are considered.

    *Josh Williams*

422 423 424 425 426 427
*   `where.not` adds `references` for `includes` like normal `where` calls do.

    Fixes #14406.

    *Yves Senn*

428 429
*   Extend fixture `$LABEL` replacement to allow string interpolation.

430 431 432 433 434 435 436 437
    Example:

        martin:
          email: $LABEL@email.com

        users(:martin).email # => martin@email.com

    *Eric Steele*
438

439 440 441 442 443 444
*   Add support for `Relation` be passed as parameter on `QueryCache#select_all`.

    Fixes #14361.

    *arthurnn*

445 446
*   Passing an Active Record object to `find` is now deprecated.  Call `.id`
    on the object first.
447

448 449
*   Passing an Active Record object to `find` or `exists?` is now deprecated.
    Call `.id` on the object first.
450

451
*   Only use BINARY for MySQL case sensitive uniqueness check when column has a case insensitive collation.
452 453 454

    *Ryuta Kamizono*

455
*   Support for MySQL 5.6 fractional seconds.
456 457 458

    *arthurnn*, *Tatsuhiko Miyagawa*

459 460 461 462 463
*   Support for Postgres `citext` data type enabling case-insensitive where
    values without needing to wrap in UPPER/LOWER sql functions.

    *Troy Kruthoff*, *Lachlan Sylvester*

464
*   Allow strings to specify the `#order` value.
465 466 467 468 469

    Example:

        Model.order(id: 'asc').to_sql == Model.order(id: :asc).to_sql

470
    *Marcelo Casiraghi*, *Robin Dupret*
471

472 473 474 475 476
*   Dynamically register PostgreSQL enum OIDs. This prevents "unknown OID"
    warnings on enum columns.

    *Dieter Komendera*

477 478 479 480 481 482 483
*   `includes` is able to detect the right preloading strategy when string
    joins are involved.

    Fixes #14109.

    *Aaron Patterson*, *Yves Senn*

484 485 486 487
*   Fixed error with validation with enum fields for records where the
    value for any enum attribute is always evaluated as 0 during
    uniqueness validation.

488
    Fixes #14172.
489 490 491

    *Vilius Luneckas* *Ahmed AbouElhamayed*

492 493 494 495 496
*   `before_add` callbacks are fired before the record is saved on
    `has_and_belongs_to_many` assocations *and* on `has_many :through`
    associations.  Before this change, `before_add` callbacks would be fired
    before the record was saved on `has_and_belongs_to_many` associations, but
    *not* on `has_many :through` associations.
497

498
    Fixes #14144.
499

500 501 502 503 504 505 506
*   Fixed STI classes not defining an attribute method if there is a
    conflicting private method defined on its ancestors.

    Fixes #11569.

    *Godfrey Chan*

507
*   Coerce strings when reading attributes. Fixes #10485.
508 509 510 511 512 513 514 515 516

    Example:

        book = Book.new(title: 12345)
        book.save!
        book.title # => "12345"

    *Yves Senn*

517 518 519 520 521 522 523 524 525 526 527
*   Deprecate half-baked support for PostgreSQL range values with excluding beginnings.
    We currently map PostgreSQL ranges to Ruby ranges. This conversion is not fully
    possible because the Ruby range does not support excluded beginnings.

    The current solution of incrementing the beginning is not correct and is now
    deprecated. For subtypes where we don't know how to increment (e.g. `#succ`
    is not defined) it will raise an ArgumentException for ranges with excluding
    beginnings.

    *Yves Senn*

528 529 530 531
*   Support for user created range types in PostgreSQL.

    *Yves Senn*

532
Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md) for previous changes.