CHANGELOG.md 28.9 KB
Newer Older
1 2 3 4
*   Fix validation on uniqueness of empty association.

    *Evgeny Li*

C
Carlos Antonio da Silva 已提交
5
*   Make `ActiveRecord::Relation#unscope` affect relations it is merged in to.
J
Jon Leighton 已提交
6 7 8

    *Jon Leighton*

9 10 11 12
*   Use strings to represent non-string `order_values`.

    *Yves Senn*

13
*   Checks to see if the record contains the foreign key to set the inverse automatically.
14 15 16

    *Edo Balvers*

17 18 19 20
*   Added `ActiveRecord::Base.to_param` for convenient "pretty" URLs derived from a model's attribute or method.

    Example:

21 22 23
        class User < ActiveRecord::Base
          to_param :name
        end
24

25 26 27
        user = User.find_by(name: 'Fancy Pants')
        user.id       # => 123
        user.to_param # => "123-fancy-pants"
28 29 30

    *Javan Makhmali*

31 32
*   Added `ActiveRecord::Base.no_touching`, which allows ignoring touch on models.

33
    Example:
34

35 36 37
        Post.no_touching do
          Post.first.touch
        end
38 39 40

    *Sam Stephenson*, *Damien Mathieu*

41
*   Prevent the counter cache from being decremented twice when destroying
42
    a record on a `has_many :through` association.
43 44 45 46 47

    Fixes #11079.

    *Dmitry Dedov*

48 49 50 51 52 53 54
*   Unify boolean type casting for `MysqlAdapter` and `Mysql2Adapter`.
    `type_cast` will return `1` for `true` and `0` for `false`.

    Fixes #11119.

    *Adam Williams*, *Yves Senn*

V
Vipul A M 已提交
55
*   Fix bug where `has_one` association record update result in crash, when replaced with itself.
56 57 58 59 60

    Fixes #12834.

    *Denis Redozubov*, *Sergio Cambra*

61 62 63 64 65 66 67 68 69
*   Log bind variables after they are type casted. This makes it more
    transparent what values are actually sent to the database.

        irb(main):002:0> Event.find("im-no-integer")
        # Before: ... WHERE "events"."id" = $1 LIMIT 1  [["id", "im-no-integer"]]
        # After: ... WHERE "events"."id" = $1 LIMIT 1  [["id", 0]]

    *Yves Senn*

70
*   Fix uninitialized constant `TransactionState` error when `Marshall.load` is used on an Active Record result.
71 72

    Fixes #12790.
73 74 75

    *Jason Ayre*

76 77 78 79
*   `.unscope` now removes conditions specified in `default_scope`.

    *Jon Leighton*

80
*   Added `ActiveRecord::QueryMethods#rewhere` which will overwrite an existing, named where condition.
81

82
    Examples:
83

84 85 86 87 88
        Post.where(trashed: true).where(trashed: false)                       #=> WHERE `trashed` = 1 AND `trashed` = 0
        Post.where(trashed: true).rewhere(trashed: false)                     #=> WHERE `trashed` = 0
        Post.where(active: true).where(trashed: true).rewhere(trashed: false) #=> WHERE `active` = 1 AND `trashed` = 0

    *DHH*
89

90
*   Extend `ActiveRecord::Base#cache_key` to take an optional list of timestamp attributes of which the highest will be used.
91

92
    Example:
93

94 95
        # last_reviewed_at will be used, if that's more recent than updated_at, or vice versa
        Person.find(5).cache_key(:updated_at, :last_reviewed_at)
96

97
    *DHH*
98

99
*   Added `ActiveRecord::Base#enum` for declaring enum attributes where the values map to integers in the database, but can be queried by name.
100

101 102 103 104 105 106 107 108 109 110 111
    Example:

        class Conversation < ActiveRecord::Base
          enum status: [:active, :archived]
        end

        Conversation::STATUS # => { active: 0, archived: 1 }

        # conversation.update! status: 0
        conversation.active!
        conversation.active? # => true
112
        conversation.status  # => "active"
113 114 115 116

        # conversation.update! status: 1
        conversation.archived!
        conversation.archived? # => true
117
        conversation.status    # => "archived"
118 119 120 121 122

        # conversation.update! status: 1
        conversation.status = :archived

    *DHH*
123

124
*   `ActiveRecord::Base#attribute_for_inspect` now truncates long arrays (more than 10 elements).
J
Jan Bernacki 已提交
125 126 127

    *Jan Bernacki*

128
*   Allow for the name of the `schema_migrations` table to be configured.
129 130 131

    *Jerad Phelps*

132 133 134 135
*   Do not add to scope includes values from through associations.
    Fixed bug when providing `includes` in through association scope, and fetching targets.

    Example:
136

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
        class Vendor < ActiveRecord::Base
          has_many :relationships, -> { includes(:user) }
          has_many :users, through: :relationships
        end

        vendor = Vendor.first

        # Before

        vendor.users.to_a # => Raises exception: not found `:user` for `User`

        # After

        vendor.users.to_a # => No exception is raised

152
    Fixes #12242, #9517, #10240.
153 154 155

    *Paul Nikitochkin*

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
*   Type cast json values on write, so that the value is consistent
    with reading from the database.

    Example:

        x = JsonDataType.new tags: {"string" => "foo", :symbol => :bar}

        # Before:
        x.tags # => {"string" => "foo", :symbol => :bar}

        # After:
        x.tags # => {"string" => "foo", "symbol" => "bar"}

    *Severin Schoepke*

171
*   `ActiveRecord::Store` works together with PG `hstore` columns.
172

173 174 175 176
    Fixes #12452.

    *Yves Senn*

177 178 179 180 181 182
*   Fix bug where `ActiveRecord::Store` used a global `Hash` to keep track of
    all registered `stored_attributes`. Now every subclass of
    `ActiveRecord::Base` has it's own `Hash`.

    *Yves Senn*

183 184
*   Save `has_one` association when primary key is manually set.

185
    Fixes #12302.
186 187 188

    *Lauro Caetano*

D
David Heinemeier Hansson 已提交
189
*    Allow any version of BCrypt when using `has_secure_password`.
190 191 192

     *Mike Perham*

193 194 195 196 197
*    Sub-query generated for `Relation` passed as array condition did not take in account
     bind values and have invalid syntax.

     Generate sub-query with inline bind values.

198
     Fixes #12586.
199 200 201

     *Paul Nikitochkin*

202 203 204 205 206
*   Fix a bug where rake db:structure:load crashed when the path contained
    spaces.

    *Kevin Mook*

207 208
*   `ActiveRecord::QueryMethods#unscope` unscopes negative equality

209
    Allows you to call `#unscope` on a relation with negative equality
210 211
    operators, i.e. `Arel::Nodes::NotIn` and `Arel::Nodes::NotEqual` that have
    been generated through the use of `where.not`.
212

213
    *Eric Hankins*
214

215 216 217 218
*   Raise an exception when model without primary key calls `.find_with_ids`.

    *Shimpei Makimoto*

219 220 221 222
*   Make `Relation#empty?` use `exists?` instead of `count`.

    *Szymon Nowak*

223 224 225 226
*   `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`.

    *Kenta Okamoto*

227 228 229 230 231 232 233
*   `NullRelation#pluck` takes a list of columns

    The method signature in `NullRelation` was updated to mimic that in
    `Calculations`.

    *Derek Prior*

234 235 236 237 238 239 240 241 242 243 244 245 246
*   `scope_chain` should not be mutated for other reflections.

    Currently `scope_chain` uses same array for building different
    `scope_chain` for different associations. During processing
    these arrays are sometimes mutated and because of in-place
    mutation the changed `scope_chain` impacts other reflections.

    Fix is to dup the value before adding to the `scope_chain`.

    Fixes #3882.

    *Neeraj Singh*

247 248 249 250 251 252
*   Prevent the inversed association from being reloaded on save.

    Fixes #9499.

    *Dmitry Polushkin*

253 254
*   Generate subquery for `Relation` if it passed as array condition for `where`
    method.
255 256

    Example:
257

258 259 260 261 262 263 264 265 266 267
        # Before
        Blog.where('id in (?)', Blog.where(id: 1))
        # =>  SELECT "blogs".* FROM "blogs"  WHERE "blogs"."id" = 1
        # =>  SELECT "blogs".* FROM "blogs"  WHERE (id IN (1))

        # After
        Blog.where('id in (?)', Blog.where(id: 1).select(:id))
        # =>  SELECT "blogs".* FROM "blogs"
        #     WHERE "blogs"."id" IN (SELECT "blogs"."id" FROM "blogs"  WHERE "blogs"."id" = 1)

268
    Fixes #12415.
269 270 271

    *Paul Nikitochkin*

272 273 274 275 276 277
*   For missed association exception message
    which is raised in `ActiveRecord::Associations::Preloader` class
    added owner record class name in order to simplify to find problem code.

    *Paul Nikitochkin*

A
Aaron Patterson 已提交
278 279 280
*   `has_and_belongs_to_many` is now transparently implemented in terms of
    `has_many :through`.  Behavior should remain the same, if not, it is a bug.

281 282 283 284 285
*   `create_savepoint`, `rollback_to_savepoint` and `release_savepoint` accept
    a savepoint name.

    *Yves Senn*

286 287 288 289
*   Make `next_migration_number` accessible for third party generators.

    *Yves Senn*

290
*   Objects instantiated using a null relationship will now retain the
291 292
    attributes of the where clause.

293
    Fixes #11676, #11675, #11376.
294 295 296

    *Paul Nikitochkin*, *Peter Brown*, *Nthalk*

A
Arthur Neves 已提交
297 298 299 300 301 302
*   Fixed `ActiveRecord::Associations::CollectionAssociation#find`
    when using `has_many` association with `:inverse_of` and finding an array of one element,
    it should return an array of one element too.

    *arthurnn*

A
Arthur Neves 已提交
303 304 305 306
*   Callbacks on has_many should access the in memory parent if a inverse_of is set.

    *arthurnn*

307 308
*   `ActiveRecord::ConnectionAdapters.string_to_time` respects
    string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
A
Arthur Neves 已提交
309

310
    Fixes #12278.
311 312 313

    *kennyj*

314 315 316 317
*   Calling `update_attributes` will now throw an `ArgumentError` whenever it
    gets a `nil` argument. More specifically, it will throw an error if the
    argument that it gets passed does not respond to to `stringify_keys`.

318
    Example:
319

320
        @my_comment.update_attributes(nil)  # => raises ArgumentError
321 322 323

    *John Wang*

324 325 326 327
*   Deprecate `quoted_locking_column` method, which isn't used anywhere.

    *kennyj*

328
*   Migration dump UUID default functions to schema.rb.
329

330 331 332 333
    Fixes #10751.

    *kennyj*

334 335 336
*   Fixed a bug in `ActiveRecord::Associations::CollectionAssociation#find_by_scan`
    when using `has_many` association with `:inverse_of` option and UUID primary key.

337 338 339 340
    Fixes #10450.

    *kennyj*

341 342 343 344
*   Fix: joins association, with defined in the scope block constraints by using several
    where constraints and at least of them is not `Arel::Nodes::Equality`,
    generates invalid SQL expression.

345
    Fixes #11963.
346 347 348

    *Paul Nikitochkin*

349
*   Deprecate the delegation of Array bang methods for associations.
350
    To use them, instead first call `#to_a` on the association to access the
351 352 353 354
    array to be acted on.

    *Ben Woosley*

355 356 357 358 359
*   `CollectionAssociation#first`/`#last` (e.g. `has_many`) use a `LIMIT`ed
    query to fetch results rather than loading the entire collection.

    *Lann Martin*

360 361 362 363
*   Make possible to run SQLite rake tasks without the `Rails` constant defined.

    *Damien Mathieu*

364 365 366 367
*   Allow Relation#from to accept other relations with bind values.

    *Ryan Wallace*

368 369 370 371 372 373
*   Fix inserts with prepared statements disabled.

    Fixes #12023.

    *Rafael Mendonça França*

374 375 376 377 378
*   Setting a has_one association on a new record no longer causes an empty
    transaction.

    *Dylan Thacker-Smith*

379 380 381 382
*   Fix `AR::Relation#merge` sometimes failing to preserve `readonly(false)` flag.

    *thedarkone*

383 384 385 386
*   Re-use `order` argument pre-processing for `reorder`.

    *Paul Nikitochkin*

R
Ryan Wallace 已提交
387 388
*   Fix PredicateBuilder so polymorphic association keys in `where` clause can
    accept objects other than direct descendants of `ActiveRecord::Base` (decorated
389 390 391 392
    models, for example).

    *Mikhail Dieterle*

393 394 395 396
*   PostgreSQL adapter recognizes negative money values formatted with
    parentheses (eg. `($1.25) # => -1.25`)).
    Fixes #11899.

397
    *Yves Senn*
398

399 400 401 402 403
*   Stop interpreting SQL 'string' columns as :string type because there is no
    common STRING datatype in SQL.

    *Ben Woosley*

404 405 406 407
*   `ActiveRecord::FinderMethods#exists?` returns `true`/`false` in all cases.

    *Xavier Noria*

408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
*   Assign inet/cidr attribute with `nil` value for invalid address.

    Example:

        record = User.new
        record.logged_in_from_ip # is type of an inet or a cidr

        # Before:
        record.logged_in_from_ip = 'bad ip address' # raise exception

        # After:
        record.logged_in_from_ip = 'bad ip address' # do not raise exception
        record.logged_in_from_ip # => nil
        record.logged_in_from_ip_before_type_cast # => 'bad ip address'

    *Paul Nikitochkin*

425 426 427 428 429 430
*   `add_to_target` now accepts a second optional `skip_callbacks` argument

    If truthy, it will skip the :before_add and :after_add callbacks.

    *Ben Woosley*

431 432 433 434 435 436 437 438 439 440 441 442 443
*   Fix interactions between `:before_add` callbacks and nested attributes
    assignment of `has_many` associations, when the association was not
    yet loaded:

    - A `:before_add` callback was being called when a nested attributes
      assignment assigned to an existing record.

    - Nested Attributes assignment did not affect the record in the
      association target when a `:before_add` callback triggered the
      loading of the association

    *Jörg Schray*

E
Eric Tipton 已提交
444
*   Allow enable_extension migration method to be revertible.
445

E
Eric Tipton 已提交
446 447
    *Eric Tipton*

448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
*   Type cast hstore values on write, so that the value is consistent
    with reading from the database.

    Example:

        x = Hstore.new tags: {"bool" => true, "number" => 5}

        # Before:
        x.tags # => {"bool" => true, "number" => 5}

        # After:
        x.tags # => {"bool" => "true", "number" => "5"}

    *Yves Senn* , *Severin Schoepke*

463 464 465 466
*   Fix multidimensional PG arrays containing non-string items.

    *Yves Senn*

467 468
*   Fixes bug when using includes combined with select, the select statement was overwritten.

469
    Fixes #11773.
470 471 472

    *Edo Balvers*

473 474 475 476
*   Load fixtures from linked folders.

    *Kassio Borges*

477 478 479 480
*   Create a directory for sqlite3 file if not present on the system.

    *Richard Schneeman*

481
*   Removed redundant override of `xml` column definition for PG,
482
    in order to use `xml` column type instead of `text`.
483 484 485

    *Paul Nikitochkin*, *Michael Nikitochkin*

486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
*   Revert `ActiveRecord::Relation#order` change that make new order
    prepend the old one.

    Before:

        User.order("name asc").order("created_at desc")
        # SELECT * FROM users ORDER BY created_at desc, name asc

    After:

        User.order("name asc").order("created_at desc")
        # SELECT * FROM users ORDER BY name asc, created_at desc

    This also affects order defined in `default_scope` or any kind of associations.

501 502 503 504 505 506 507 508 509 510
*   Add ability to define how a class is converted to Arel predicates.
    For example, adding a very vendor specific regex implementation:

        regex_handler = proc do |column, value|
          Arel::Nodes::InfixOperation.new('~', column, value.source)
        end
        ActiveRecord::PredicateBuilder.register_handler(Regexp, regex_handler)

    *Sean Griffin & @joannecheng*

511 512 513 514 515 516 517 518 519
*   Don't allow `quote_value` to be called without a column.

    Some adapters require column information to do their job properly.
    By enforcing the provision of the column for this internal method
    we ensure that those using adapters that require column information
    will always get the proper behavior.

    *Ben Woosley*

520
*   When using optimistic locking, `update` was not passing the column to `quote_value`
521
    to allow the connection adapter to properly determine how to quote the value. This was
R
Rajarshi Das 已提交
522
    affecting certain databases that use specific column types.
523

524
    Fixes #6763.
525 526 527

    *Alfred Wong*

528 529
*   rescue from all exceptions in `ConnectionManagement#call`

530
    Fixes #11497.
531 532 533 534 535 536 537 538 539 540 541

    As `ActiveRecord::ConnectionAdapters::ConnectionManagement` middleware does
    not rescue from Exception (but only from StandardError), the Connection
    Pool quickly runs out of connections when multiple erroneous Requests come
    in right after each other.

    Rescuing from all exceptions and not just StandardError, fixes this
    behaviour.

    *Vipul A M*

542 543 544 545
*   `change_column` for PostgreSQL adapter respects the `:array` option.

    *Yves Senn*

546 547 548 549
*   Remove deprecation warning from `attribute_missing` for attributes that are columns.

    *Arun Agrawal*

550 551
*   Remove extra decrement of transaction deep level.

552
    Fixes #4566.
553 554 555

    *Paul Nikitochkin*

K
kennyj 已提交
556 557 558
*   Reset @column_defaults when assigning `locking_column`.
    We had a potential problem. For example:

559 560 561 562
      class Post < ActiveRecord::Base
        self.column_defaults  # if we call this unintentionally before setting locking_column ...
        self.locking_column = 'my_locking_column'
      end
K
kennyj 已提交
563

564 565
      Post.column_defaults["my_locking_column"]
      => nil # expected value is 0 !
K
kennyj 已提交
566 567 568

    *kennyj*

569 570 571
*   Remove extra select and update queries on save/touch/destroy ActiveRecord model
    with belongs to reflection with option `touch: true`.

572
    Fixes #11288.
573 574 575

    *Paul Nikitochkin*

576 577 578 579 580
*   Remove deprecated nil-passing to the following `SchemaCache` methods:
    `primary_keys`, `tables`, `columns` and `columns_hash`.

    *Yves Senn*

581 582 583 584
*   Remove deprecated block filter from `ActiveRecord::Migrator#migrate`.

    *Yves Senn*

585 586 587 588
*   Remove deprecated String constructor from `ActiveRecord::Migrator`.

    *Yves Senn*

589 590 591 592
*   Remove deprecated `scope` use without passing a callable object.

    *Arun Agrawal*

593 594 595 596 597
*   Remove deprecated `transaction_joinable=` in favor of `begin_transaction`
    with `:joinable` option.

    *Arun Agrawal*

598 599 600 601
*   Remove deprecated `decrement_open_transactions`.

    *Arun Agrawal*

602 603 604 605
*   Remove deprecated `increment_open_transactions`.

    *Arun Agrawal*

606 607 608 609 610
*   Remove deprecated `PostgreSQLAdapter#outside_transaction?`
    method. You can use `#transaction_open?` instead.

    *Yves Senn*

611 612 613 614 615
*   Remove deprecated `ActiveRecord::Fixtures.find_table_name` in favor of
    `ActiveRecord::Fixtures.default_fixture_model_name`.

    *Vipul A M*

616 617 618 619
*   Removed deprecated `columns_for_remove` from `SchemaStatements`.

    *Neeraj Singh*

620 621 622 623
*   Remove deprecated `SchemaStatements#distinct`.

    *Francesco Rodriguez*

624 625 626 627 628 629
*   Move deprecated `ActiveRecord::TestCase` into the rails test
    suite. The class is no longer public and is only used for internal
    Rails tests.

    *Yves Senn*

630 631 632 633 634
*   Removed support for deprecated option `:restrict` for `:dependent`
    in associations.

    *Neeraj Singh*

635 636 637 638
*   Removed support for deprecated `delete_sql` in associations.

    *Neeraj Singh*

639 640 641 642
*   Removed support for deprecated `insert_sql` in associations.

    *Neeraj Singh*

643 644 645 646
*   Removed support for deprecated `finder_sql` in associations.

    *Neeraj Singh*

647 648 649 650
*   Support array as root element in JSON fields.

    *Alexey Noskov & Francesco Rodriguez*

651 652 653 654
*   Removed support for deprecated `counter_sql` in associations.

    *Neeraj Singh*

655
*   Do not invoke callbacks when `delete_all` is called on collection.
656

657 658 659
    Method `delete_all` should not be invoking callbacks and this
    feature was deprecated in Rails 4.0. This is being removed.
    `delete_all` will continue to honor the `:dependent` option. However
660
    if `:dependent` value is `:destroy` then the `:delete_all` deletion
661 662 663
    strategy for that collection will be applied.

    User can also force a deletion strategy by passing parameter to
664
    `delete_all`. For example you can do `@post.comments.delete_all(:nullify)`.
665 666 667

    *Neeraj Singh*

668 669 670 671
*   Calling default_scope without a proc will now raise `ArgumentError`.

    *Neeraj Singh*

672 673 674 675
*   Removed deprecated method `type_cast_code` from Column.

    *Neeraj Singh*

676 677 678 679 680 681 682 683
*   Removed deprecated options `delete_sql` and `insert_sql` from HABTM
    association.

    Removed deprecated options `finder_sql` and `counter_sql` from
    collection association.

    *Neeraj Singh*

684 685 686 687 688
*   Remove deprecated `ActiveRecord::Base#connection` method.
    Make sure to access it via the class.

    *Yves Senn*

689 690 691 692
*   Remove deprecation warning for `auto_explain_threshold_in_seconds`.

    *Yves Senn*

693 694 695 696
*   Remove deprecated `:distinct` option from `Relation#count`.

    *Yves Senn*

697 698 699 700 701
*   Removed deprecated methods `partial_updates`, `partial_updates?` and
    `partial_updates=`.

    *Neeraj Singh*

N
Neeraj Singh 已提交
702 703 704 705
*   Removed deprecated method `scoped`

    *Neeraj Singh*

706 707 708 709
*   Removed deprecated method `default_scopes?`

    *Neeraj Singh*

710 711 712 713 714 715 716 717 718 719 720 721
*   Remove implicit join references that were deprecated in 4.0.

    Example:

        # before with implicit joins
        Comment.where('posts.author_id' => 7)

        # after
        Comment.references(:posts).where('posts.author_id' => 7)

    *Yves Senn*

722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
*   Apply default scope when joining associations. For example:

        class Post < ActiveRecord::Base
          default_scope -> { where published: true }
        end

        class Comment
          belongs_to :post
        end

    When calling `Comment.joins(:post)`, we expect to receive only
    comments on published posts, since that is the default scope for
    posts.

    Before this change, the default scope from `Post` was not applied,
    so we'd get comments on unpublished posts.

    *Jon Leighton*

741 742 743 744
*   Remove `activerecord-deprecated_finders` as a dependency

    *Łukasz Strzałkowski*

745 746 747 748
*   Remove Oracle / Sqlserver / Firebird database tasks that were deprecated in 4.0.

    *kennyj*

749 750 751 752 753
*   `find_each` now returns an `Enumerator` when called without a block, so that it
    can be chained with other `Enumerable` methods.

    *Ben Woosley*

754 755 756 757 758
*   `ActiveRecord::Result.each` now returns an `Enumerator` when called without
     a block, so that it can be chained with other `Enumerable` methods.

    *Ben Woosley*

759
*   Flatten merged join_values before building the joins.
760

761 762 763 764 765 766 767 768
    While joining_values special treatment is given to string values.
    By flattening the array it ensures that string values are detected
    as strings and not arrays.

    Fixes #10669.

    *Neeraj Singh and iwiznia*

769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
*   Do not load all child records for inverse case.

    currently `post.comments.find(Comment.first.id)` would load all
    comments for the given post to set the inverse association.

    This has a huge performance penalty. Because if post has 100k
    records and all these 100k records would be loaded in memory
    even though the comment id was supplied.

    Fix is to use in-memory records only if loaded? is true. Otherwise
    load the records using full sql.

    Fixes #10509.

    *Neeraj Singh*

785 786 787 788 789 790 791 792 793 794 795
*   `inspect` on Active Record model classes does not initiate a
    new connection. This means that calling `inspect`, when the
    database is missing, will no longer raise an exception.
    Fixes #10936.

    Example:

        Author.inspect # => "Author(no database connection)"

    *Yves Senn*

796 797 798 799 800
*   Handle single quotes in PostgreSQL default column values.
    Fixes #10881.

    *Dylan Markow*

801 802 803 804 805 806 807 808 809 810 811
*   Log the sql that is actually sent to the database.

    If I have a query that produces sql
    `WHERE "users"."name" = 'a         b'` then in the log all the
    whitespace is being squeezed. So the sql that is printed in the
    log is `WHERE "users"."name" = 'a b'`.

    Do not squeeze whitespace out of sql queries. Fixes #10982.

    *Neeraj Singh*

V
Vijay Dev 已提交
812
*   Fixture setup no longer depends on `ActiveRecord::Base.configurations`.
813 814 815 816
    This is relevant when `ENV["DATABASE_URL"]` is used in place of a `database.yml`.

    *Yves Senn*

817 818 819 820 821
*   Fix mysql2 adapter raises the correct exception when executing a query on a
    closed connection.

    *Yves Senn*

822 823 824
*   Ambiguous reflections are on :through relationships are no longer supported.
    For example, you need to change this:

825 826 827 828
        class Author < ActiveRecord::Base
          has_many :posts
          has_many :taggings, :through => :posts
        end
829

830 831 832 833
        class Post < ActiveRecord::Base
          has_one :tagging
          has_many :taggings
        end
834

835 836
        class Tagging < ActiveRecord::Base
        end
837 838 839

    To this:

840 841 842 843
        class Author < ActiveRecord::Base
          has_many :posts
          has_many :taggings, :through => :posts, :source => :tagging
        end
844

845 846 847 848
        class Post < ActiveRecord::Base
          has_one :tagging
          has_many :taggings
        end
849

850 851
        class Tagging < ActiveRecord::Base
        end
852

853
    *Aaron Patterson*
854

855
*   Remove column restrictions for `count`, let the database raise if the SQL is
856
    invalid. The previous behavior was untested and surprising for the user.
857 858 859 860 861 862 863 864 865 866 867 868 869 870
    Fixes #5554.

    Example:

        User.select("name, username").count
        # Before => SELECT count(*) FROM users
        # After => ActiveRecord::StatementInvalid

        # you can still use `count(:all)` to perform a query unrelated to the
        # selected columns
        User.select("name, username").count(:all) # => SELECT count(*) FROM users

    *Yves Senn*

871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
*   Rails now automatically detects inverse associations. If you do not set the
    `:inverse_of` option on the association, then Active Record will guess the
    inverse association based on heuristics.

    Note that automatic inverse detection only works on `has_many`, `has_one`,
    and `belongs_to` associations. Extra options on the associations will
    also prevent the association's inverse from being found automatically.

    The automatic guessing of the inverse association uses a heuristic based
    on the name of the class, so it may not work for all associations,
    especially the ones with non-standard names.

    You can turn off the automatic detection of inverse associations by setting
    the `:inverse_of` option to `false` like so:

886 887 888
        class Taggable < ActiveRecord::Base
          belongs_to :tag, inverse_of: false
        end
889 890 891

    *John Wang*

892 893 894 895
*   Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432

    *Adam Anderson*

896 897 898 899 900 901 902 903 904 905 906 907
*   Usage of `implicit_readonly` is being removed`. Please use `readonly` method
    explicitly to mark records as `readonly.
    Fixes #10615.

    Example:

        user = User.joins(:todos).select("users.*, todos.title as todos_title").readonly(true).first
        user.todos_title = 'clean pet'
        user.save! # will raise error

    *Yves Senn*

908 909 910 911 912
*   Fix the `:primary_key` option for `has_many` associations.
    Fixes #10693.

    *Yves Senn*

913
*   Fix bug where tiny types are incorrectly coerced as boolean when the length is more than 1.
914 915 916

    Fixes #10620.

917
    *Aaron Patterson*
918

P
Prathamesh Sonpatki 已提交
919
*   Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1.
920 921 922

    *kennyj*

923 924 925
*   Deprecate `ConnectionAdapters::SchemaStatements#distinct`,
    as it is no longer used by internals.

926
    *Ben Woosley*
927

928 929
*   Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
    is not blank.
930

931 932 933 934 935 936 937
    Call `assume_migrated_upto_version` on connection to prevent it from first
    being picked up in `method_missing`.

    In the base class, `Migration`, `method_missing` expects the argument to be a
    table name, and calls `proper_table_name` on the arguments before sending to
    `connection`. If `table_name_prefix` or `table_name_suffix` is used, the schema
    version changes to `prefix_version_suffix`, breaking `rake test:prepare`.
938 939 940 941 942

    Fixes #10411.

    *Kyle Stevens*

943
*   Method `read_attribute_before_type_cast` should accept input as symbol.
944 945 946

    *Neeraj Singh*

947 948 949 950
*   Confirm a record has not already been destroyed before decrementing counter cache.

    *Ben Tucker*

951 952
*   Fixed a bug in `ActiveRecord#sanitize_sql_hash_for_conditions` in which
    `self.class` is an argument to `PredicateBuilder#build_from_hash`
953
    causing `PredicateBuilder` to call non-existent method
954
    `Class#reflect_on_association`.
955 956 957

    *Zach Ohlgren*

958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
*   While removing index if column option is missing then raise IrreversibleMigration exception.

    Following code should raise `IrreversibleMigration`. But the code was
    failing since options is an array and not a hash.

        def change
          change_table :users do |t|
            t.remove_index [:name, :email]
          end
        end

    Fix was to check if the options is a Hash before operating on it.

    Fixes #10419.

    *Neeraj Singh*

975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
*   Do not overwrite manually built records during one-to-one nested attribute assignment

    For one-to-one nested associations, if you build the new (in-memory)
    child object yourself before assignment, then the NestedAttributes
    module will not overwrite it, e.g.:

        class Member < ActiveRecord::Base
          has_one :avatar
          accepts_nested_attributes_for :avatar

          def avatar
            super || build_avatar(width: 200)
          end
        end

        member = Member.new
        member.avatar_attributes = {icon: 'sad'}
        member.avatar.width # => 200

    *Olek Janiszewski*

996 997
*   fixes bug introduced by #3329. Now, when autosaving associations,
    deletions happen before inserts and saves. This prevents a 'duplicate
998 999 1000 1001 1002
    unique value' database error that would occur if a record being created had
    the same value on a unique indexed field as that of a record being destroyed.

    *Johnny Holton*

1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
*   Handle aliased attributes in ActiveRecord::Relation.

    When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:

    With the model

        class Topic
          alias_attribute :heading, :title
        end

    The call

        Topic.where(heading: 'The First Topic')

    should yield the same result as

        Topic.where(title: 'The First Topic')

    This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`.

    This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`.

    *Godfrey Chan*

1027 1028 1029 1030
*   Mute `psql` output when running rake db:schema:load.

    *Godfrey Chan*

1031 1032 1033 1034 1035 1036
*   Trigger a save on `has_one association=(associate)` when the associate contents have changed.

    Fix #8856.

    *Chris Thompson*

1037 1038 1039
*   Abort a rake task when missing db/structure.sql like `db:schema:load` task.

    *kennyj*
1040

1041
*   rake:db:test:prepare falls back to original environment after execution.
1042

1043
    *Slava Markevich*
1044

1045 1046 1047 1048 1049 1050
*   Raise `ActiveRecord::RecordNotDestroyed` when a replaced child marked with `dependent: destroy` fails to be destroyed.

    Fix #12812

    *Brian Thomas Storti*

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