diff options
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r-- | activerecord/CHANGELOG.md | 235 |
1 files changed, 223 insertions, 12 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 43651c9b48..52f5f0efa3 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,220 @@ +* Fix `PostgreSQL` insert to properly extract table name from multiline string SQL. + + Previously, executing an insert SQL in `PostgreSQL` with a command like this: + + insert into articles( + number) + values( + 5152 + ) + + would not work because the adapter was unable to extract the correct `articles` + table name. + + *Kuldeep Aggarwal* + +* `Relation` no longer has mutator methods like `#map!` and `#delete_if`. Convert + to an `Array` by calling `#to_a` before using these methods. + + It intends to prevent odd bugs and confusion in code that call mutator + methods directly on the `Relation`. + + Example: + + # Instead of this + Author.where(name: 'Hank Moody').compact! + + # Now you have to do this + authors = Author.where(name: 'Hank Moody').to_a + authors.compact! + + *Lauro Caetano* + +* Better support for `where()` conditions that use a `belongs_to` + association name. + + Using the name of an association in `where` previously worked only + if the value was a single `ActiveRecord::Base` object. e.g. + + Post.where(author: Author.first) + + Any other values, including `nil`, would cause invalid SQL to be + generated. This change supports arguments in the `where` query + conditions where the key is a `belongs_to` association name and the + value is `nil`, an `Array` of `ActiveRecord::Base` objects, or an + `ActiveRecord::Relation` object. + + class Post < ActiveRecord::Base + belongs_to :author + end + + `nil` value finds records where the association is not set: + + Post.where(author: nil) + # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL + + `Array` values find records where the association foreign key + matches the ids of the passed ActiveRecord models, resulting + in the same query as `Post.where(author_id: [1,2])`: + + authors_array = [Author.find(1), Author.find(2)] + Post.where(author: authors_array) + # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IN (1, 2) + + `ActiveRecord::Relation` values find records using the same + query as `Post.where(author_id: Author.where(last_name: "Emde"))` + + Post.where(author: Author.where(last_name: "Emde")) + # SELECT "posts".* FROM "posts" + # WHERE "posts"."author_id" IN ( + # SELECT "authors"."id" FROM "authors" + # WHERE "authors"."last_name" = 'Emde') + + Polymorphic `belongs_to` associations will continue to be handled + appropriately, with the polymorphic `association_type` field added + to the query to match the base class of the value. This feature + previously only worked when the value was a single `ActveRecord::Base`. + + class Post < ActiveRecord::Base + belongs_to :author, polymorphic: true + end + + Post.where(author: Author.where(last_name: "Emde")) + # Generates a query similar to: + Post.where(author_id: Author.where(last_name: "Emde"), author_type: "Author") + + *Martin Emde* + +* Respect temporary option when dropping tables with MySQL. + + Normal DROP TABLE also works, but commits the transaction. + + drop_table :temporary_table, temporary: true + + *Cody Cutrer* + +* Add option to create tables from a query. + + create_table(:long_query, temporary: true, + as: "SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id") + + Generates: + + CREATE TEMPORARY TABLE long_query AS + SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id + + *Cody Cutrer* + +* `db:test:clone` and `db:test:prepare` must load Rails environment. + + `db:test:clone` and `db:test:prepare` use `ActiveRecord::Base`. configurations, + so we need to load the Rails environment, otherwise the config wont be in place. + + *arthurnn* + +* Use the right column to type cast grouped calculations with custom expressions. + + Fixes #13230. + + Example: + + # Before + Account.group(:firm_name).sum('0.01 * credit_limit') + # => { '37signals' => '0.5' } + + # After + Account.group(:firm_name).sum('0.01 * credit_limit') + # => { '37signals' => 0.5 } + + *Paul Nikitochkin* + +* Polymorphic `belongs_to` associations with the `touch: true` option set update the timestamps of + the old and new owner correctly when moved between owners of different types. + + Example: + + class Rating < ActiveRecord::Base + belongs_to :rateable, polymorphic: true, touch: true + end + + rating = Rating.create rateable: Song.find(1) + rating.update_attributes rateable: Book.find(2) # => timestamps of Song(1) and Book(2) are updated + + *Severin Schoepke* + +* Improve formatting of migration exception messages: make them easier to read + with line breaks before/after, and improve the error for pending migrations. + + *John Bachir* + +* Fix `last` with `offset` to return the proper record instead of always the last one. + + Example: + + Model.offset(4).last + # => returns the 4th record from the end. + + Fixes #7441. + + *kostya*, *Lauro Caetano* + +* `type_to_sql` returns a `String` for unmapped columns. This fixes an error + when using unmapped array types in PG + + Example: + + change_colum :table, :column, :bigint, array: true + + Fixes #13146. + + *Jens Fahnenbruck*, *Yves Senn* + +* Fix `QueryCache` to work with nested blocks, so that it will only clear the existing cache + after leaving the outer block instead of clearing it right after the inner block is finished. + + *Vipul A M* + +* The ERB in fixture files is no longer evaluated in the context of the main + object. Helper methods used by multiple fixtures should be defined on the + class object returned by `ActiveRecord::FixtureSet.context_class`. + + *Victor Costan* + +* Previously, the `has_one` macro incorrectly accepted the `counter_cache` + option, but never actually supported it. Now it will raise an `ArgumentError` + when using `has_one` with `counter_cache`. + + *Godfrey Chan* + +* Implement `rename_index` natively for MySQL >= 5.7. + + *Cody Cutrer* + +* Fix bug when validating the uniqueness of an aliased attribute. + + Fixes #12402. + + *Lauro Caetano* + +* Update counter cache on a `has_many` relationship regardless of default scope. + + Fix #12952. + + *Uku Taht* + +* `rename_index` adds the new index before removing the old one. This allows to + rename indexes on columns with a foreign key and prevents the following error: + + Cannot drop index 'index_engines_on_car_id': needed in a foreign key constraint + + *Cody Cutrer*, *Yves Senn* + +* Raise `ActiveRecord::RecordNotDestroyed` when a replaced child marked with `dependent: destroy` fails to be destroyed. + + Fix #12812 + + *Brian Thomas Storti* + * Fix validation on uniqueness of empty association. *Evgeny Li* @@ -52,7 +269,7 @@ *Adam Williams*, *Yves Senn* -* Fix bug where `has_one` associaton record update result in crash, when replaced with itself. +* Fix bug where `has_one` association record update result in crash, when replaced with itself. Fixes #12834. @@ -346,12 +563,6 @@ *Paul Nikitochkin* -* Deprecate the delegation of Array bang methods for associations. - To use them, instead first call `#to_a` on the association to access the - array to be acted on. - - *Ben Woosley* - * `CollectionAssociation#first`/`#last` (e.g. `has_many`) use a `LIMIT`ed query to fetch results rather than loading the entire collection. @@ -699,11 +910,11 @@ *Neeraj Singh* -* Removed deprecated method `scoped` +* Removed deprecated method `scoped`. *Neeraj Singh* -* Removed deprecated method `default_scopes?` +* Removed deprecated method `default_scopes?`. *Neeraj Singh* @@ -738,7 +949,7 @@ *Jon Leighton* -* Remove `activerecord-deprecated_finders` as a dependency +* Remove `activerecord-deprecated_finders` as a dependency. *Łukasz Strzałkowski* @@ -824,7 +1035,7 @@ class Author < ActiveRecord::Base has_many :posts - has_many :taggings, :through => :posts + has_many :taggings, through: :posts end class Post < ActiveRecord::Base @@ -839,7 +1050,7 @@ class Author < ActiveRecord::Base has_many :posts - has_many :taggings, :through => :posts, :source => :tagging + has_many :taggings, through: :posts, source: :tagging end class Post < ActiveRecord::Base |