diff options
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r-- | activerecord/CHANGELOG.md | 1605 |
1 files changed, 1032 insertions, 573 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index b679d64472..614cee4449 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,1028 +1,1487 @@ -* No verbose backtrace by db:drop when database does not exist. +* Set `scope.reordering_value` to `true` if :reordering values are specified. - Fixes #16295. + Fixes #21886. - *Kenn Ejima* + *Hiroaki Izu* -* Add support for Postgresql JSONB. +* Add support for bidirectional destroy dependencies. + + Fixes #13609. Example: - create_table :posts do |t| - t.jsonb :meta_data + class Content < ActiveRecord::Base + has_one :position, dependent: :destroy end - *Philippe Creux*, *Chris Teague* + class Position < ActiveRecord::Base + belongs_to :content, dependent: :destroy + end -* `db:purge` with MySQL respects `Rails.env`. + *Seb Jacobs* - *Yves Senn* +* Includes HABTM returns correct size now. It's caused by the join dependency + only instantiates one HABTM object because the join table hasn't a primary key. -* `change_column_default :table, :column, nil` with PostgreSQL will issue a - `DROP DEFAULT` instead of a `DEFAULT NULL` query. + Fixes #16032. - Fixes #16261. + Examples: - *Matthew Draper*, *Yves Senn* + before: + + Project.first.salaried_developers.size # => 3 + Project.includes(:salaried_developers).first.salaried_developers.size # => 1 -* Allow to specify a type for the foreign key column in `references` - and `add_reference`. + after: + + Project.first.salaried_developers.size # => 3 + Project.includes(:salaried_developers).first.salaried_developers.size # => 3 + + *Bigxiang* + +* Add option to index errors in nested attributes + + For models which have nested attributes, errors within those models will + now be indexed if :index_errors is specified when defining a + has_many relationship, or if its set in the global config. Example: - change_table :vehicle do |t| - t.references :station, type: :uuid + class Guitar < ActiveRecord::Base + has_many :tuning_pegs + accepts_nested_attributes_for :tuning_pegs end - *Andrey Novikov*, *Łukasz Sarnacki* + class TuningPeg < ActiveRecord::Base + belongs_to :guitar + validates_numericality_of :pitch + end -* `create_join_table` removes a common prefix when generating the join table. - This matches the existing behavior of HABTM associations. + - Old style + - `guitar.errors["tuning_pegs.pitch"] = ["is not a number"]` - Fixes #13683. + - New style (if defined globally, or set in has_many_relationship) + - `guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]` - *Stefan Kanev* + *Michael Probber and Terence Sun* -* Dont swallow errors on compute_type when having a bad alias_method on - a class. +* Exit with non-zero status for failed database rake tasks. - *arthurnn* + *Jay Hayes* -* PostgreSQL invalid `uuid` are convert to nil. +* Queries such as `Computer.joins(:monitor).group(:status).count` will now be + interpreted as `Computer.joins(:monitor).group('computers.status').count` + so that when `Computer` and `Monitor` have both `status` columns we don't + have conflicts in projection. - *Abdelkader Boudih* + *Rafael Sales* -* Restore 4.0 behavior for using serialize attributes with `JSON` as coder. +* Add ability to default to `uuid` as primary key when generating database migrations - With 4.1.x, `serialize` started returning a string when `JSON` was passed as - the second attribute. It will now return a hash as per previous versions. + config.generators do |g| + g.orm :active_record, primary_key_type: :uuid + end - Example: + *Jon McCartie* - class Post < ActiveRecord::Base - serialize :comment, JSON - end +* Don't cache arguments in #find_by if they are an ActiveRecord::Relation - class Comment - include ActiveModel::Model - attr_accessor :category, :text - end + Fixes #20817 - post = Post.create! - post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.") - post.save! + *Hiroaki Izu* - # 4.0 - post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."} +* Qualify column name inserted by `group` in calculation - # 4.1 before - post.comment # => "#<Comment:0x007f80ab48ff98>" + Giving `group` an unqualified column name now works, even if the relation + has `JOIN` with another table which also has a column of the name. - # 4.1 after - post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."} + *Soutaro Matsumoto* - When using `JSON` as the coder in `serialize`, Active Record will use the - new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to - `ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped - correctly using the `#as_json` hook. +* Don't cache prepared statements containing an IN clause or a SQL literal, as + these queries will change often and are unlikely to have a cache hit. - To keep the previous behaviour, supply a custom coder instead - ([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)). + *Sean Griffin* - Fixes #15594. +* Fix `rewhere` in a `has_many` association. - *Jenn Cooper* + Fixes #21955. -* Do not use `RENAME INDEX` syntax for MariaDB 10.0. + *Josh Branchaud*, *Kal* - Fixes #15931. +* `where` raises ArgumentError on unsupported types. - *Jeff Browning* + Fixes #20473. -* Calling `#empty?` on a `has_many` association would use the value from the - counter cache if one exists. + *Jake Worth* - *David Verhasselt* +* Add an immutable string type to help reduce memory usage for apps which do + not need mutation detection on Strings. -* Fix the schema dump generated for tables without constraints and with - primary key with default value of custom PostgreSQL function result. + *Sean Griffin* - Fixes #16111. +* Give `AcriveRecord::Relation#update` its own deprecation warning when + passed an `ActiveRecord::Base` instance. - *Andrey Novikov* + Fixes #21945. -* Fix the SQL generated when a `delete_all` is run on an association to not - produce an `IN` statements. + *Ted Johansson* - Before: +* Make it possible to pass `:to_table` when adding a foreign key through + `add_reference`. - UPDATE "categorizations" SET "category_id" = NULL WHERE - "categorizations"."category_id" = 1 AND "categorizations"."id" IN (1, 2) + Fixes #21563. - After: + *Yves Senn* - UPDATE "categorizations" SET "category_id" = NULL WHERE - "categorizations"."category_id" = 1 +* No longer pass depreacted option `-i` to `pg_dump`. - *Eileen M. Uchitelle, Aaron Patterson* + *Paul Sadauskas* -* Avoid type casting boolean and ActiveSupport::Duration values to numeric - values for string columns. Otherwise, in some database, the string column - values will be coerced to a numeric allowing false or 0.seconds match any - string starting with a non-digit. +* Concurrent `AR::Base#increment!` and `#decrement!` on the same record + are all reflected in the database rather than overwriting each other. - Example: + *Bogdan Gusiev* - App.where(apikey: false) # => SELECT * FROM users WHERE apikey = '0' +* Avoid leaking the first relation we call `first` on, per model. - *Dylan Thacker-Smith* + Fixes #21921. -* Add a `:required` option to singular associations, providing a nicer - API for presence validations on associations. + *Matthew Draper*, *Jean Boussier* + +* Remove unused `pk_and_sequence_for` in AbstractMysqlAdapter. + + *Ryuta Kamizono* + +* Allow fixtures files to set the model class in the YAML file itself. + + To load the fixtures file `accounts.yml` as the `User` model, use: + + _fixture: + model_class: User + david: + name: David + + Fixes #9516. + + *Roque Pinel* + +* Don't require a database connection to load a class which uses acceptance + validations. *Sean Griffin* -* Fixed error in `reset_counters` when associations have `select` scope. - (Call to `count` generates invalid SQL.) +* Correctly apply `unscope` when preloading through associations. - *Cade Truitt* + *Jimmy Bourassa* -* After a successful `reload`, `new_record?` is always false. +* Fixed taking precision into count when assigning a value to timestamp attribute - Fixes #12101. + Timestamp column can have less precision than ruby timestamp + In result in how big a fraction of a second can be stored in the + database. - *Matthew Draper* -* PostgreSQL renaming table doesn't attempt to rename non existent sequences. + m = Model.create! + m.created_at.usec == m.reload.created_at.usec # => false + # due to different precision in Time.now and database column - *Abdelkader Boudih* + If the precision is low enough, (mysql default is 0, so it is always low + enough by default) the value changes when model is reloaded from the + database. This patch fixes that issue ensuring that any timestamp + assigned as an attribute is converted to column precision under the + attribute. -* Move 'dependent: :destroy' handling for 'belongs_to' - from 'before_destroy' to 'after_destroy' callback chain + *Bogdan Gusiev* - Fixes #12380. +* Introduce `connection.data_sources` and `connection.data_source_exists?`. + These methods determine what relations can be used to back Active Record + models (usually tables and views). - *Ivan Antropov* + Also deprecate `SchemaCache#tables`, `SchemaCache#table_exists?` and + `SchemaCache#clear_table_cache!` in favor of their new data source + counterparts. -* Detect in-place modifications on String attributes. + *Yves Senn*, *Matthew Draper* - Before this change user have to mark the attribute as changed to it be persisted - in the database. Now it is not required anymore. +* Add `ActiveRecord::Base.ignored_columns` to make some columns + invisible from ActiveRecord. - Before: + *Jean Boussier* - user = User.first - user.name << ' Griffin' - user.name_will_change! - user.save - user.reload.name # => "Sean Griffin" +* `ActiveRecord::Tasks::MySQLDatabaseTasks` fails if shellout to + mysql commands (like `mysqldump`) is not successful. - After: + *Steve Mitchell* - user = User.first - user.name << ' Griffin' - user.save - user.reload.name # => "Sean Griffin" +* Ensure `select` quotes aliased attributes, even when using `from`. - *Sean Griffin* + Fixes #21488 + + *Sean Griffin & @johanlunds* + +* MySQL: support `unsigned` numeric data types. + + Example: + + create_table :foos do |t| + t.unsigned_integer :quantity + t.unsigned_bigint :total + t.unsigned_float :percentage + t.unsigned_decimal :price, precision: 10, scale: 2 + end + + The `unsigned: true` option may be used for the primary key: -* Add `ActiveRecord::Base#validate!` that raises `RecordInvalid` if the record - is invalid. + create_table :foos, id: :bigint, unsigned: true do |t| + … + end + + *Ryuta Kamizono* + +* Add `#views` and `#view_exists?` methods on connection adapters. + + *Ryuta Kamizono* + +* Correctly dump composite primary key. + + Example: + + create_table :barcodes, primary_key: ["region", "code"] do |t| + t.string :region + t.integer :code + end + + *Ryuta Kamizono* + +* Lookup the attribute name for `restrict_with_error` messages on the + model class that defines the association. + + *kuboon*, *Ronak Jangir* + +* Correct query for PostgreSQL 8.2 compatibility. + + *Ben Murphy*, *Matthew Draper* + +* `bin/rake db:migrate` uses + `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of + `Migrator.migrations_paths`. + + *Tobias Bielohlawek* + +* Support dropping indexes concurrently in PostgreSQL. - *Bogdan Gusiev*, *Marc Schütz* + See http://www.postgresql.org/docs/9.4/static/sql-dropindex.html for more + details. -* Support for adding and removing foreign keys. Foreign keys are now - a part of `schema.rb`. This is supported by Mysql2Adapter, MysqlAdapter - and PostgreSQLAdapter. + *Grey Baker* - Many thanks to *Matthew Higgins* for laying the foundation with his work on - [foreigner](https://github.com/matthuhiggins/foreigner). +* Deprecate passing conditions to `ActiveRecord::Relation#delete_all` + and `ActiveRecord::Relation#destroy_all`. + + *Wojciech Wnętrzak* + +* PostgreSQL, `create_schema`, `drop_schema` and `rename_table` now quote + schema names. + + Fixes #21418. Example: - # within your migrations: - add_foreign_key :articles, :authors - remove_foreign_key :articles, :authors + create_schema("my.schema") + # CREATE SCHEMA "my.schema"; *Yves Senn* -* Fix subtle bugs regarding attribute assignment on models with no primary - key. `'id'` will no longer be part of the attributes hash. +* PostgreSQL, add `:if_exists` option to `#drop_schema`. This makes it + possible to drop a schema that might exist without raising an exception if + it doesn't. - *Sean Griffin* + *Yves Senn* -* Deprecate automatic counter caches on `has_many :through`. The behavior was - broken and inconsistent. +* Only try to nullify has_one target association if the record is persisted. - *Sean Griffin* + Fixes #21223. + + *Agis Anastasopoulos* + +* Uniqueness validator raises descriptive error when running on a persisted + record without primary key. + + Fixes #21304. + + *Yves Senn* + +* Add a native JSON data type support in MySQL. + + Example: + + create_table :json_data_type do |t| + t.json :settings + end + + *Ryuta Kamizono* -* `preload` preserves readonly flag for associations. +* Descriptive error message when fixtures contain a missing column. - See #15853. + Fixes #21201. *Yves Senn* -* Assume numeric types have changed if they were assigned to a value that - would fail numericality validation, regardless of the old value. Previously - this would only occur if the old value was 0. +* `ActiveRecord::Tasks::PostgreSQLDatabaseTasks` fail if shellout to + postgresql commands (like `pg_dump`) is not successful. + + *Bryan Paxton*, *Nate Berkopec* + +* Add `ActiveRecord::Relation#in_batches` to work with records and relations + in batches. + + Available options are `of` (batch size), `load`, `begin_at`, and `end_at`. + + Examples: + + Person.in_batches.each_record(&:party_all_night!) + Person.in_batches.update_all(awesome: true) + Person.in_batches.delete_all + Person.in_batches.each do |relation| + relation.delete_all + sleep 10 # Throttles the delete queries + end + + Fixes #20933. + + *Sina Siadat* + +* Added methods for PostgreSQL geometric data types to use in migrations. + + Example: + + create_table :foo do |t| + t.line :foo_line + t.lseg :foo_lseg + t.box :foo_box + t.path :foo_path + t.polygon :foo_polygon + t.circle :foo_circle + end + + *Mehmet Emin İNAÇ* + +* Add `cache_key` to ActiveRecord::Relation. Example: - model = Model.create!(number: 5) - model.number = '5wibble' - model.number_changed? # => true + @users = User.where("name like ?", "%Alberto%") + @users.cache_key + # => "/users/query-5942b155a43b139f2471b872ac54251f-3-20150714212107656125000" + + *Alberto Fernández-Capel* + +* Properly allow uniqueness validations on primary keys. - Fixes #14731. + Fixes #20966. + + *Sean Griffin*, *presskey* + +* Don't raise an error if an association failed to destroy when `destroy` was + called on the parent (as opposed to `destroy!`). + + Fixes #20991. *Sean Griffin* -* `reload` no longer merges with the existing attributes. - The attribute hash is fully replaced. The record is put into the same state - as it would be with `Model.find(model.id)`. +* `ActiveRecord::RecordNotFound` modified to store model name, primary_key and + id of the caller model. It allows the catcher of this exception to make + a better decision to what to do with it. + + Example: + + class SomeAbstractController < ActionController::Base + rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404 + + private def redirect_to_404(e) + return redirect_to(posts_url) if e.model == 'Post' + raise + end + end + + *Sameer Rahmani* + +* Deprecate the keys for association `restrict_dependent_destroy` errors in favor + of new key names. + + Previously `has_one` and `has_many` associations were using the + `one` and `many` keys respectively. Both of these keys have special + meaning in I18n (they are considered to be pluralizations) so by + renaming them to `has_one` and `has_many` we make the messages more explicit + and most importantly they don't clash with linguistical systems that need to + validate translation keys (and their pluralizations). + + The `:'restrict_dependent_destroy.one'` key should be replaced with + `:'restrict_dependent_destroy.has_one'`, and `:'restrict_dependent_destroy.many'` + with `:'restrict_dependent_destroy.has_many'`. + + *Roque Pinel*, *Christopher Dell* + +* Fix state being carried over from previous transaction. + + Considering the following example where `name` is a required attribute. + Before we had `new_record?` returning `true` for a persisted record: + + author = Author.create! name: 'foo' + author.name = nil + author.save # => false + author.new_record? # => true + + Fixes #20824. + + *Roque Pinel* + +* Correctly ignore `mark_for_destruction` when `autosave` isn't set to `true` + when validating associations. + + Fixes #20882. *Sean Griffin* -* The object returned from `select_all` must respond to `column_types`. - If this is not the case a `NoMethodError` is raised. +* Fix a bug where counter_cache doesn't always work with polymorphic + relations. + + Fixes #16407. + + *Stefan Kanev*, *Sean Griffin* + +* Ensure that cyclic associations with autosave don't cause duplicate errors + to be added to the parent record. + + Fixes #20874. *Sean Griffin* -* `has_many :through` associations will no longer save the through record - twice when added in an `after_create` callback defined before the - associations. +* Ensure that `ActionController::Parameters` can still be passed to nested + attributes. - Fixes #3798. + Fixes #20922. *Sean Griffin* -* Detect in-place modifications of PG array types +* Deprecate force association reload by passing a truthy argument to + association method. + + For collection association, you can call `#reload` on association proxy to + force a reload: + + @user.posts.reload # Instead of @user.posts(true) + + For singular association, you can call `#reload` on the parent object to + clear its association cache then call the association method: + + @user.reload.profile # Instead of @user.profile(true) + + Passing a truthy argument to force association to reload will be removed in + Rails 5.1. + + *Prem Sichanugrist* + +* Replaced `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch` + from the concurrent-ruby gem. + + *Jerry D'Antonio* + +* Fix through associations using scopes having the scope merged multiple + times. + + Fixes #20721. + Fixes #20727. *Sean Griffin* -* Add `bin/rake db:purge` task to empty the current database. +* `ActiveRecord::Base.dump_schema_after_migration` applies migration tasks + other than `db:migrate`. (eg. `db:rollback`, `db:migrate:dup`, ...) + + Fixes #20743. *Yves Senn* -* Deprecate `serialized_attributes` without replacement. +* Add alternate syntax to make `change_column_default` reversible. - *Sean Griffin* + User can pass in `:from` and `:to` to make `change_column_default` command + become reversible. + + Example: + + change_column_default :posts, :status, from: nil, to: "draft" + change_column_default :users, :authorized, from: true, to: false + + *Prem Sichanugrist* + +* Prevent error when using `force_reload: true` on an unassigned polymorphic + belongs_to association. + + Fixes #20426. + + *James Dabbs* -* Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets - are part of the URI structure, not the actual host. +* Correctly raise `ActiveRecord::AssociationTypeMismatch` when assigning + a wrong type to a namespaced association. - Fixes #15705. + Fixes #20545. - *Andy Bakun*, *Aaron Stone* + *Diego Carrion* -* Ensure both parent IDs are set on join records when both sides of a - through association are new. +* `validates_absence_of` respects `marked_for_destruction?`. + + Fixes #20449. + + *Yves Senn* + +* Include the `Enumerable` module in `ActiveRecord::Relation` + + *Sean Griffin & bogdan* + +* Use `Enumerable#sum` in `ActiveRecord::Relation` if a block is given. *Sean Griffin* -* `ActiveRecord::Dirty` now detects in-place changes to mutable values. - Serialized attributes on ActiveRecord models will no longer save when - unchanged. +* Let `WITH` queries (Common Table Expressions) be explainable. + + *Vladimir Kochnev* + +* Make `remove_index :table, :column` reversible. + + *Yves Senn* + +* Fixed an error which would occur in dirty checking when calling + `update_attributes` from a getter. - Fixes #8328. + Fixes #20531. *Sean Griffin* -* Pluck now works when selecting columns from different tables with the same - name. +* Make `remove_foreign_key` reversible. Any foreign key options must be + specified, similar to `remove_column`. + + *Aster Ryan* + +* Add `:_prefix` and `:_suffix` options to `enum` definition. + + Fixes #17511, #17415. + + *Igor Kapkov* - Fixes #15649. +* Correctly handle decimal arrays with defaults in the schema dumper. + + Fixes #20515. + + *Sean Griffin & jmondo* + +* Deprecate the PostgreSQL `:point` type in favor of a new one which will return + `Point` objects instead of an `Array` *Sean Griffin* -* Remove `cache_attributes` and friends. All attributes are cached. +* Ensure symbols passed to `ActiveRecord::Relation#select` are always treated + as columns. + + Fixes #20360. *Sean Griffin* -* Remove deprecated method `ActiveRecord::Base.quoted_locking_column`. +* Do not set `sql_mode` if `strict: :default` is specified. + + # config/database.yml + production: + adapter: mysql2 + database: foo_prod + user: foo + strict: :default + + *Ryuta Kamizono* + +* Allow proc defaults to be passed to the attributes API. See documentation + for examples. + + *Sean Griffin*, *Kir Shatrov* + +* SQLite: `:collation` support for string and text columns. + + Example: + + create_table :foo do |t| + t.string :string_nocase, collation: 'NOCASE' + t.text :text_rtrim, collation: 'RTRIM' + end + + add_column :foo, :title, :string, collation: 'RTRIM' + + change_column :foo, :title, :string, collation: 'NOCASE' *Akshay Vishnoi* -* `ActiveRecord::FinderMethods.find` with block can handle proc parameter as - `Enumerable#find` does. +* Allow the use of symbols or strings to specify enum values in test + fixtures: - Fixes #15382. + awdr: + title: "Agile Web Development with Rails" + status: :proposed - *James Yang* + *George Claghorn* -* Make timezone aware attributes work with PostgreSQL array columns. +* Clear query cache when `ActiveRecord::Base#reload` is called. - Fixes #13402. + *Shane Hender, Pierre Nespo* - *Kuldeep Aggarwal*, *Sean Griffin* +* Include stored procedures and function on the MySQL structure dump. -* `ActiveRecord::SchemaMigration` has no primary key regardless of the - `primary_key_prefix_type` configuration. + *Jonathan Worek* - Fixes #15051. +* Pass `:extend` option for `has_and_belongs_to_many` associations to the + underlying `has_many :through`. - *JoseLuis Torres*, *Yves Senn* + *Jaehyun Shin* -* `rake db:migrate:status` works with legacy migration numbers like `00018_xyz.rb`. +* Deprecate `Relation#uniq` use `Relation#distinct` instead. - Fixes #15538. + See #9683. *Yves Senn* -* Baseclass becomes! subclass. +* Allow single table inheritance instantiation to work when storing + demodulized class names. - Before this change, a record which changed its STI type, could not be - updated. + *Alex Robbin* - Fixes #14785. +* Correctly pass MySQL options when using `structure_dump` or + `structure_load`. - *Matthew Draper*, *Earl St Sauver*, *Edo Balvers* + Specifically, it fixes an issue when using SSL authentication. -* Remove deprecated `ActiveRecord::Migrator.proper_table_name`. Use the - `proper_table_name` instance method on `ActiveRecord::Migration` instead. + *Alex Coomans* - *Akshay Vishnoi* +* Dump indexes in `create_table` instead of `add_index`. -* Fix regression on eager loading association based on SQL query rather than - existing column. + If the adapter supports indexes in `create_table`, generated SQL is + slightly more efficient. - Fixes #15480. + *Ryuta Kamizono* - *Lauro Caetano*, *Carlos Antonio da Silva* +* Correctly dump `:options` on `create_table` for MySQL. -* Deprecate returning `nil` from `column_for_attribute` when no column exists. - It will return a null object in Rails 5.0 + *Ryuta Kamizono* - *Sean Griffin* +* PostgreSQL: `:collation` support for string and text columns. -* Implemented ActiveRecord::Base#pretty_print to work with PP. + Example: - *Ethan* + create_table :foos do |t| + t.string :string_en, collation: 'en_US.UTF-8' + t.text :text_ja, collation: 'ja_JP.UTF-8' + end -* Preserve type when dumping PostgreSQL point, bit, bit varying and money - columns. + *Ryuta Kamizono* - *Yves Senn* +* Remove `ActiveRecord::Serialization::XmlSerializer` from core. -* New records remain new after YAML serialization. + *Zachary Scott* - *Sean Griffin* +* Make `unscope` aware of "less than" and "greater than" conditions. -* PostgreSQL support default values for enum types. Fixes #7814. + *TAKAHASHI Kazuaki* - *Yves Senn* +* `find_by` and `find_by!` raise `ArgumentError` when called without + arguments. + + *Kohei Suzuki* -* PostgreSQL `default_sequence_name` respects schema. Fixes #7516. +* Revert behavior of `db:schema:load` back to loading the full + environment. This ensures that initializers are run. + + Fixes #19545. *Yves Senn* -* Fixed `columns_for_distinct` of postgresql adapter to work correctly - with orders without sort direction modifiers. +* Fix missing index when using `timestamps` with the `index` option. - *Nikolay Kondratyev* + The `index` option used with `timestamps` should be passed to both + `column` definitions for `created_at` and `updated_at` rather than just + the first. -* PostgreSQL `reset_pk_sequence!` respects schemas. Fixes #14719. + *Paul Mucur* - *Yves Senn* +* Rename `:class` to `:anonymous_class` in association options. -* Keep PostgreSQL `hstore` and `json` attributes as `Hash` in `@attributes`. - Fixes duplication in combination with `store_accessor`. + Fixes #19659. - Fixes #15369. + *Andrew White* - *Yves Senn* +* Autosave existing records on a has many through association when the parent + is new. -* `rake railties:install:migrations` respects the order of railties. + Fixes #19782. - *Arun Agrawal* + *Sean Griffin* -* Fix redefine a has_and_belongs_to_many inside inherited class - Fixing regression case, where redefining the same has_an_belongs_to_many - definition into a subclass would raise. +* Fixed a bug where uniqueness validations would error on out of range values, + even if an validation should have prevented it from hitting the database. - Fixes #14983. + *Andrey Voronkov* - *arthurnn* +* MySQL: `:charset` and `:collation` support for string and text columns. + + Example: -* Fix has_and_belongs_to_many public reflection. - When defining a has_and_belongs_to_many, internally we convert that to two has_many. - But as `reflections` is a public API, people expect to see the right macro. + create_table :foos do |t| + t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin' + t.text :text_ascii, charset: 'ascii' + end - Fixes #14682. + *Ryuta Kamizono* - *arthurnn* +* Foreign key related methods in the migration DSL respect + `ActiveRecord::Base.pluralize_table_names = false`. + + Fixes #19643. + + *Mehmet Emin İNAÇ* -* Fixed serialization for records with an attribute named `format`. +* Reduce memory usage from loading types on PostgreSQL. - Fixes #15188. + Fixes #19578. - *Godfrey Chan* + *Sean Griffin* -* When a `group` is set, `sum`, `size`, `average`, `minimum` and `maximum` - on a NullRelation should return a Hash. +* Add `config.active_record.warn_on_records_fetched_greater_than` option. - *Kuldeep Aggarwal* + When set to an integer, a warning will be logged whenever a result set + larger than the specified size is returned by a query. -* Fixed serialized fields returning serialized data after being updated with - `update_column`. + Fixes #16463. - *Simon Hørup Eskildsen* + *Jason Nochlin* -* Fixed polymorphic eager loading when using a String as foreign key. +* Ignore `.psqlrc` when loading database structure. - Fixes #14734. + *Jason Weathered* - *Lauro Caetano* +* Fix referencing wrong table aliases while joining tables of has many through + association (only when calling calculation methods). -* Change belongs_to touch to be consistent with timestamp updates + Fixes #19276. - If a model is set up with a belongs_to: touch relationship the parent - record will only be touched if the record was modified. This makes it - consistent with timestamp updating on the record itself. + *pinglamb* - *Brock Trappitt* +* Correctly persist a serialized attribute that has been returned to + its default value by an in-place modification. -* Fixed the inferred table name of a has_and_belongs_to_many auxiliar - table inside a schema. + Fixes #19467. - Fixes #14824. + *Matthew Draper* - *Eric Chahin* +* Fix generating the schema file when using PostgreSQL `BigInt[]` data type. + Previously the `limit: 8` was not coming through, and this caused it to + become `Int[]` data type after rebuilding from the schema. -* Remove unused `:timestamp` type. Transparently alias it to `:datetime` - in all cases. Fixes inconsistencies when column types are sent outside of - `ActiveRecord`, such as for XML Serialization. + Fixes #19420. - *Sean Griffin* + *Jake Waller* -* Fix bug that added `table_name_prefix` and `table_name_suffix` to - extension names in PostgreSQL when migrating. +* Reuse the `CollectionAssociation#reader` cache when the foreign key is + available prior to save. - *Joao Carlos* + *Ben Woosley* -* The `:index` option in migrations, which previously was only available for - `references`, now works with any column types. +* Add `config.active_record.dump_schemas` to fix `db:structure:dump` + when using schema_search_path and PostgreSQL extensions. - *Marc Schütz* + Fixes #17157. -* Add support for counter name to be passed as parameter on `CounterCache::ClassMethods#reset_counters`. + *Ryan Wallace* - *jnormore* +* Renaming `use_transactional_fixtures` to `use_transactional_tests` for clarity. -* Restrict deletion of record when using `delete_all` with `uniq`, `group`, `having` - or `offset`. + Fixes #18864. - In these cases the generated query ignored them and that caused unintended - records to be deleted. + *Brandon Weiss* - Fixes #11985. +* Increase pg gem version requirement to `~> 0.18`. Earlier versions of the + pg gem are known to have problems with Ruby 2.2. - *Leandro Facchinetti* + *Matt Brictson* -* Floats with limit >= 25 that get turned into doubles in MySQL no longer have - their limit dropped from the schema. +* Correctly dump `serial` and `bigserial`. - Fixes #14135. + *Ryuta Kamizono* - *Aaron Nelson* +* Fix default `format` value in `ActiveRecord::Tasks::DatabaseTasks#schema_file`. -* Fix how to calculate associated class name when using namespaced has_and_belongs_to_many - association. + *James Cox* - Fixes #14709. +* Don't enroll records in the transaction if they don't have commit callbacks. + This was causing a memory leak when creating many records inside a transaction. - *Kassio Borges* + Fixes #15549. -* `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and - strings in column names as equal. + *Will Bryant*, *Aaron Patterson* - 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. +* Correctly create through records when created on a has many through + association when using `where`. - *Nat Budin* + Fixes #19073. -* Fix `stored_attributes` to correctly merge the details of stored - attributes defined in parent classes. + *Sean Griffin* - Fixes #14672. +* Add `SchemaMigration.create_table` support for any unicode charsets with MySQL. - *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy* + *Ryuta Kamizono* -* `change_column_default` allows `[]` as argument to `change_column_default`. +* PostgreSQL no longer disables user triggers if system triggers can't be + disabled. Disabling user triggers does not fulfill what the method promises. + Rails currently requires superuser privileges for this method. - Fixes #11586. + If you absolutely rely on this behavior, consider patching + `disable_referential_integrity`. *Yves Senn* -* Handle `name` and `"char"` column types in the PostgreSQL adapter. +* Restore aborted transaction state when `disable_referential_integrity` fails + due to missing permissions. - `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. + *Toby Ovod-Everett*, *Yves Senn* - *J Smith*, *Yves Senn* +* In PostgreSQL, print a warning message if `disable_referential_integrity` + fails due to missing permissions. -* Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and - NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN` + *Andrey Nering*, *Yves Senn* - Before: +* Allow a `:limit` option for MySQL bigint primary key support. - Point.create(value: 1.0/0) - Point.last.value # => 0.0 + Example: - After: + create_table :foos, id: :primary_key, limit: 8 do |t| + end - Point.create(value: 1.0/0) - Point.last.value # => Infinity + # or + + create_table :foos, id: false do |t| + t.primary_key :id, limit: 8 + end - *Innokenty Mikhailov* + *Ryuta Kamizono* -* Allow the PostgreSQL adapter to handle bigserial primary key types again. +* `belongs_to` will now trigger a validation error by default if the association is not present. + You can turn this off on a per-association basis with `optional: true`. + (Note this new default only applies to new Rails apps that will be generated with + `config.active_record.belongs_to_required_by_default = true` in initializer.) - Fixes #10410. + *Josef Šimánek* - *Patrick Robertson* +* Fixed `ActiveRecord::Relation#becomes!` and `changed_attributes` issues for type + columns. -* 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 #17139. - Fixes #15024. + *Miklos Fazekas* - *Yves Senn* +* Format the time string according to the precision of the time column. -* Fixed has_and_belongs_to_many's CollectionAssociation size calculation. + *Ryuta Kamizono* - has_and_belongs_to_many should fall back to using the normal CollectionAssociation's - size calculation if the collection is not cached or loaded. +* Allow a `:precision` option for time type columns. - Fixes #14913, #14914. + *Ryuta Kamizono* - *Fred Wu* +* Add `ActiveRecord::Base.suppress` to prevent the receiver from being saved + during the given block. -* Return a non zero status when running `rake db:migrate:status` and migration table does - not exist. + For example, here's a pattern of creating notifications when new comments + are posted. (The notification may in turn trigger an email, a push + notification, or just appear in the UI somewhere): - *Paul B.* + class Comment < ActiveRecord::Base + belongs_to :commentable, polymorphic: true + after_create -> { Notification.create! comment: self, + recipients: commentable.recipients } + end -* Add support for module-level `table_name_suffix` in models. + That's what you want the bulk of the time. A new comment creates a new + Notification. There may be edge cases where you don't want that, like + when copying a commentable and its comments, in which case write a + concern with something like this: + + module Copyable + def copy_to(destination) + Notification.suppress do + # Copy logic that creates new comments that we do not want triggering + # notifications. + end + end + end - This makes `table_name_suffix` work the same way as `table_name_prefix` when - using namespaced models. + *Michael Ryan* - *Jenner LaFave* +* `:time` option added for `#touch`. -* Revert the behaviour of `ActiveRecord::Relation#join` changed through 4.0 => 4.1 to 4.0. + Fixes #18905. - In 4.1.0 `Relation#join` is delegated to `Arel#SelectManager`. - In 4.0 series it is delegated to `Array#join`. + *Hyonjee Joo* - *Bogdan Gusiev* +* Deprecate passing of `start` value to `find_in_batches` and `find_each` + in favour of `begin_at` value. -* Log nil binary column values correctly. + *Vipul A M* - 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. +* Add `foreign_key_exists?` method. - *James Coleman* + *Tõnis Simo* -* Rails will now pass a custom validation context through to autosave associations - in order to validate child associations with the same context. +* Use SQL COUNT and LIMIT 1 queries for `none?` and `one?` methods + if no block or limit is given, instead of loading the entire + collection into memory. This applies to relations (e.g. `User.all`) + as well as associations (e.g. `account.users`) - Fixes #13854. + # Before: - *Eric Chahin*, *Aaron Nelson*, *Kevin Casey* + users.none? + # SELECT "users".* FROM "users" -* Stringify all variables keys of MySQL connection configuration. + users.one? + # SELECT "users".* FROM "users" - When `sql_mode` variable for MySQL adapters set in configuration as `String` - was ignored and overwritten by strict mode option. + # After: - Fixes #14895. + users.none? + # SELECT 1 AS one FROM "users" LIMIT 1 - *Paul Nikitochkin* + users.one? + # SELECT COUNT(*) FROM "users" -* Ensure SQLite3 statements are closed on errors. + *Eugene Gilburg* - Fixes #13631. +* Have `enum` perform type casting consistently with the rest of Active + Record, such as `where`. - *Timur Alperovich* + *Sean Griffin* -* Give ActiveRecord::PredicateBuilder private methods the privacy they deserve. +* `scoping` no longer pollutes the current scope of sibling classes when using + STI. e.x. - *Hector Satre* + StiOne.none.scoping do + StiTwo.all + end -* 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 #18806. - Fixes #14845. + *Sean Griffin* - *Kassio Borges* +* `remove_reference` with `foreign_key: true` removes the foreign key before + removing the column. This fixes a bug where it was not possible to remove + the column on MySQL. -* Reset the cache when modifying a Relation with cached Arel. - Additionally display a warning message to make the user aware. + Fixes #18664. *Yves Senn* -* PostgreSQL should internally use `:datetime` consistently for TimeStamp. Assures - different spellings of timestamps are treated the same. +* `find_in_batches` now accepts an `:end_at` parameter that complements the `:start` + parameter to specify where to stop batch processing. - Example: + *Vipul A M* - mytimestamp.simplified_type('timestamp without time zone') - # => :datetime - mytimestamp.simplified_type('timestamp(6) without time zone') - # => also :datetime (previously would be :timestamp) +* Fix a rounding problem for PostgreSQL timestamp columns. - See #14513. + If a timestamp column has a precision specified, it needs to + format according to that. - *Jefferson Lai* + *Ryuta Kamizono* -* `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions. +* Respect the database default charset for `schema_migrations` table. - Fixes #14841. + The charset of `version` column in `schema_migrations` table depends + on the database default charset and collation rather than the encoding + of the connection. - *Lucas Mazza* + *Ryuta Kamizono* -* Fix name collision with `Array#select!` with `Relation#select!`. +* Raise `ArgumentError` when passing `nil` or `false` to `Relation#merge`. - Fixes #14752. + These are not valid values to merge in a relation, so it should warn users + early. - *Earl St Sauver* + *Rafael Mendonça França* -* Fixed unexpected behavior for `has_many :through` associations going through a scoped `has_many`. +* Use `SCHEMA` instead of `DB_STRUCTURE` for specifying a structure file. - 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. + This makes the db:structure tasks consistent with test:load_structure. - Fixes #14537. + *Dieter Komendera* - *Jan Habermann* +* Respect custom primary keys for associations when calling `Relation#where` -* `@destroyed` should always be set to `false` when an object is duped. + Fixes #18813. - *Kuldeep Aggarwal* + *Sean Griffin* -* Fixed has_many association to make it support irregular inflections. +* Fix several edge cases which could result in a counter cache updating + twice or not updating at all for `has_many` and `has_many :through`. - Fixes #8928. + Fixes #10865. - *arthurnn*, *Javier Goizueta* + *Sean Griffin* -* Fixed a problem where count used with a grouping was not returning a Hash. +* Foreign keys added by migrations were given random, generated names. This + meant a different `structure.sql` would be generated every time a developer + ran migrations on their machine. - Fixes #14721. + The generated part of foreign key names is now a hash of the table name and + column name, which is consistent every time you run the migration. - *Eric Chahin* + *Chris Sinjakli* -* `sanitize_sql_like` helper method to escape a string for safe use in an SQL - LIKE statement. +* Validation errors would be raised for parent records when an association + was saved when the parent had `validate: false`. It should not be the + responsibility of the model to validate an associated object unless the + object was created or modified by the parent. - Example: + This fixes the issue by skipping validations if the parent record is + persisted, not changed, and not marked for destruction. - class Article - def self.search(term) - where("title LIKE ?", sanitize_sql_like(term)) - end - end + Fixes #17621. - Article.search("20% _reduction_") - # => Query looks like "... title LIKE '20\% \_reduction\_' ..." + *Eileen M. Uchitelle, Aaron Patterson* - *Rob Gilson*, *Yves Senn* +* Fix n+1 query problem when eager loading nil associations (fixes #18312) -* Do not quote uuid default value on `change_column`. + *Sammy Larbi* - Fixes #14604. +* Change the default error message from `can't be blank` to `must exist` for + the presence validator of the `:required` option on `belongs_to`/`has_one` + associations. - *Eric Chahin* + *Henrik Nygren* -* The comparison between `Relation` and `CollectionProxy` should be consistent. +* Fixed `ActiveRecord::Relation#group` method when an argument is an SQL + reserved keyword: Example: - author.posts == Post.where(author_id: author.id) - # => true - Post.where(author_id: author.id) == author.posts - # => true + SplitTest.group(:key).count + Property.group(:value).count - Fixes #13506. + *Bogdan Gusiev* - *Lauro Caetano* +* Added the `#or` method on `ActiveRecord::Relation`, allowing use of the OR + operator to combine WHERE or HAVING clauses. -* Calling `delete_all` on an unloaded `CollectionProxy` no longer - generates an SQL statement containing each id of the collection: + Example: - Before: + Post.where('id = 1').or(Post.where('id = 2')) + # => SELECT * FROM posts WHERE (id = 1) OR (id = 2) - DELETE FROM `model` WHERE `model`.`parent_id` = 1 - AND `model`.`id` IN (1, 2, 3...) + *Sean Griffin*, *Matthew Draper*, *Gael Muller*, *Olivier El Mekki* - After: +* Don't define autosave association callbacks twice from + `accepts_nested_attributes_for`. - DELETE FROM `model` WHERE `model`.`parent_id` = 1 + Fixes #18704. - *Eileen M. Uchitelle*, *Aaron Patterson* + *Sean Griffin* -* Fixed error for aggregate methods (`empty?`, `any?`, `count`) with `select` - which created invalid SQL. +* Integer types will no longer raise a `RangeError` when assigning an + attribute, but will instead raise when going to the database. - Fixes #13648. + Fixes several vague issues which were never reported directly. See the + commit message from the commit which added this line for some examples. - *Simon Woker* + *Sean Griffin* -* PostgreSQL adapter only warns once for every missing OID per connection. +* Values which would error while being sent to the database (such as an + ASCII-8BIT string with invalid UTF-8 bytes on SQLite3), no longer error on + assignment. They will still error when sent to the database, but you are + given the ability to re-assign it to a valid value. - Fixes #14275. + Fixes #18580. - *Matthew Draper*, *Yves Senn* + *Sean Griffin* -* PostgreSQL adapter automatically reloads it's type map when encountering - unknown OIDs. +* Don't remove join dependencies in `Relation#exists?` - Fixes #14678. + Fixes #18632. - *Matthew Draper*, *Yves Senn* + *Sean Griffin* -* Fix insertion of records via `has_many :through` association with scope. +* Invalid values assigned to a JSON column are assumed to be `nil`. - Fixes #3548. + Fixes #18629. - *Ivan Antropov* + *Sean Griffin* -* Auto-generate stable fixture UUIDs on PostgreSQL. +* Add `ActiveRecord::Base#accessed_fields`, which can be used to quickly + discover which fields were read from a model when you are looking to only + select the data you need from the database. - Fixes #11524. + *Sean Griffin* - *Roderick van Domburg* +* Introduce the `:if_exists` option for `drop_table`. -* Fixed a problem where an enum would overwrite values of another enum - with the same name in an unrelated class. + Example: - Fixes #14607. + drop_table(:posts, if_exists: true) - *Evan Whalen* + That would execute: -* PostgreSQL and SQLite string columns no longer have a default limit of 255. + DROP TABLE IF EXISTS posts - Fixes #13435, #9153. + If the table doesn't exist, `if_exists: false` (the default) raises an + exception whereas `if_exists: true` does nothing. - *Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn* + *Cody Cutrer*, *Stefan Kanev*, *Ryuta Kamizono* -* Make possible to have an association called `records`. +* Don't run SQL if attribute value is not changed for update_attribute method. - Fixes #11645. + *Prathamesh Sonpatki* - *prathamesh-sonpatki* +* `time` columns can now get affected by `time_zone_aware_attributes`. If you have + set `config.time_zone` to a value other than `'UTC'`, they will be treated + as in that time zone by default in Rails 5.1. If this is not the desired + behavior, you can set -* `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. + ActiveRecord::Base.time_zone_aware_types = [:datetime] - Fixes #14003. + A deprecation warning will be emitted if you have a `:time` column, and have + not explicitly opted out. - *Jefferson Lai* + Fixes #3145. -* Block a few default Class methods as scope name. + *Sean Griffin* - For instance, this will raise: +* Tests now run after_commit callbacks. You no longer have to declare + `uses_transaction ‘test name’` to test the results of an after_commit. - scope :public, -> { where(status: 1) } + after_commit callbacks run after committing a transaction whose parent + is not `joinable?`: un-nested transactions, transactions within test cases, + and transactions in `console --sandbox`. - *arthurnn* + *arthurnn*, *Ravil Bayramgalin*, *Matthew Draper* -* Fixed error when using `with_options` with lambda. +* `nil` as a value for a binary column in a query no longer logs as + "<NULL binary data>", and instead logs as just "nil". - Fixes #9805. + *Sean Griffin* - *Lauro Caetano* +* `attribute_will_change!` will no longer cause non-persistable attributes to + be sent to the database. -* Switch `sqlite3:///` URLs (which were temporarily - deprecated in 4.1) from relative to absolute. + Fixes #18407. - If you still want the previous interpretation, you should replace - `sqlite3:///my/path` with `sqlite3:my/path`. + *Sean Griffin* - *Matthew Draper* +* Remove support for the `protected_attributes` gem. -* Treat blank UUID values as `nil`. + *Carlos Antonio da Silva*, *Roberto Miranda* - Example: +* Fix accessing of fixtures having non-string labels like Fixnum. - Sample.new(uuid_field: '') #=> <Sample id: nil, uuid_field: nil> + *Prathamesh Sonpatki* - *Dmitry Lavrov* +* Remove deprecated support to preload instance-dependent associations. -* Enable support for materialized views on PostgreSQL >= 9.3. + *Yves Senn* - *Dave Lee* +* Remove deprecated support for PostgreSQL ranges with exclusive lower bounds. -* The PostgreSQL adapter supports custom domains. Fixes #14305. + *Yves Senn* + +* Remove deprecation when modifying a relation with cached Arel. + This raises an `ImmutableRelation` error instead. *Yves Senn* -* 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`. +* Added `ActiveRecord::SecureToken` in order to encapsulate generation of + unique tokens for attributes in a model using `SecureRandom`. - See #7814. + *Roberto Miranda* - *Yves Senn* +* Change the behavior of boolean columns to be closer to Ruby's semantics. -* Fixed error when specifying a non-empty default value on a PostgreSQL array column. + Before this change we had a small set of "truthy", and all others are "falsy". - Fixes #10613. + Now, we have a small set of "falsy" values and all others are "truthy" matching + Ruby's semantics. - *Luke Steensen* + *Rafael Mendonça França* -* Fixed error where .persisted? throws SystemStackError for an unsaved model with a - custom primary key that didn't save due to validation error. +* Deprecate `ActiveRecord::Base.errors_in_transactional_callbacks=`. - Fixes #14393. + *Rafael Mendonça França* - *Chris Finne* +* Change transaction callbacks to not swallow errors. -* Introduce `validate` as an alias for `valid?`. + Before this change any errors raised inside a transaction callback + were getting rescued and printed in the logs. - This is more intuitive when you want to run validations but don't care about the return value. + Now these errors are not rescued anymore and just bubble up, as the other callbacks. - *Henrik Nyh* + *Rafael Mendonça França* -* Create indexes inline in CREATE TABLE for MySQL. +* Remove deprecated `sanitize_sql_hash_for_conditions`. - This is important, because adding an index on a temporary table after it has been created - would commit the transaction. + *Rafael Mendonça França* - It also allows creating and dropping indexed tables with fewer queries and fewer permissions - required. +* Remove deprecated `Reflection#source_macro`. - Example: + *Rafael Mendonça França* - 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 +* Remove deprecated `symbolized_base_class` and `symbolized_sti_name`. - *Cody Cutrer*, *Steve Rice*, *Rafael Mendonça Franca* + *Rafael Mendonça França* -* Use singular table name in generated migrations when - `ActiveRecord::Base.pluralize_table_names` is `false`. +* Remove deprecated `ActiveRecord::Base.disable_implicit_join_references=`. - Fixes #13426. + *Rafael Mendonça França* - *Kuldeep Aggarwal* +* Remove deprecated access to connection specification using a string accessor. -* `touch` accepts many attributes to be touched at once. + Now all strings will be handled as a URL. - Example: + *Rafael Mendonça França* - # touches :signed_at, :sealed_at, and :updated_at/on attributes. - Photo.last.touch(:signed_at, :sealed_at) +* Change the default `null` value for `timestamps` to `false`. - *James Pinto* + *Rafael Mendonça França* -* `rake db:structure:dump` only dumps schema information if the schema - migration table exists. +* Return an array of pools from `connection_pools`. - Fixes #14217. + *Rafael Mendonça França* - *Yves Senn* +* Return a null column from `column_for_attribute` when no column exists. -* 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. + *Rafael Mendonça França* - *Matthew Draper* +* Remove deprecated `serialized_attributes`. -* `pk_and_sequence_for` now ensures that only the pg_depend entries - pointing to pg_class, and thus only sequence objects, are considered. + *Rafael Mendonça França* - *Josh Williams* +* Remove deprecated automatic counter caches on `has_many :through`. -* `where.not` adds `references` for `includes` like normal `where` calls do. + *Rafael Mendonça França* - Fixes #14406. +* Change the way in which callback chains can be halted. - *Yves Senn* + The preferred method to halt a callback chain from now on is to explicitly + `throw(:abort)`. + In the past, returning `false` in an Active Record `before_` callback had the + side effect of halting the callback chain. + This is not recommended anymore and, depending on the value of the + `ActiveSupport.halt_callback_chains_on_return_false` option, will + either not work at all or display a deprecation warning. -* Extend fixture `$LABEL` replacement to allow string interpolation. + *claudiob* - Example: +* Clear query cache on rollback. - martin: - email: $LABEL@email.com + *Florian Weingarten* - users(:martin).email # => martin@email.com +* Fix setting of foreign_key for through associations when building a new record. - *Eric Steele* + Fixes #12698. -* Add support for `Relation` be passed as parameter on `QueryCache#select_all`. + *Ivan Antropov* - Fixes #14361. +* Improve dumping of the primary key. If it is not a default primary key, + correctly dump the type and options. - *arthurnn* + Fixes #14169, #16599. + + *Ryuta Kamizono* + +* Format the datetime string according to the precision of the datetime field. -* Passing an Active Record object to `find` or `exists?` is now deprecated. - Call `.id` on the object first. + Incompatible to rounding behavior between MySQL 5.6 and earlier. - *Aaron Patterson* + In 5.5, when you insert `2014-08-17 12:30:00.999999` the fractional part + is ignored. In 5.6, it's rounded to `2014-08-17 12:30:01`: -* Only use BINARY for MySQL case sensitive uniqueness check when column has a case insensitive collation. + http://bugs.mysql.com/bug.php?id=68760 *Ryuta Kamizono* -* Support for MySQL 5.6 fractional seconds. +* Allow a precision option for MySQL datetimes. - *arthurnn*, *Tatsuhiko Miyagawa* + *Ryuta Kamizono* -* Support for Postgres `citext` data type enabling case-insensitive where - values without needing to wrap in UPPER/LOWER sql functions. +* Fixed automatic `inverse_of` for models nested in a module. - *Troy Kruthoff*, *Lachlan Sylvester* + *Andrew McCloud* -* Only save has_one associations if record has changes. - Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one - object did not get saved to the db. +* Change `ActiveRecord::Relation#update` behavior so that it can + be called without passing ids of the records to be updated. - *Alan Kennedy* + This change allows updating multiple records returned by + `ActiveRecord::Relation` with callbacks and validations. -* Allow strings to specify the `#order` value. + # Before + # ArgumentError: wrong number of arguments (1 for 2) + Comment.where(group: 'expert').update(body: "Group of Rails Experts") - Example: + # After + # Comments with group expert updated with body "Group of Rails Experts" + Comment.where(group: 'expert').update(body: "Group of Rails Experts") - Model.order(id: 'asc').to_sql == Model.order(id: :asc).to_sql + *Prathamesh Sonpatki* - *Marcelo Casiraghi*, *Robin Dupret* +* Fix `reaping_frequency` option when the value is a string. -* Dynamically register PostgreSQL enum OIDs. This prevents "unknown OID" - warnings on enum columns. + This usually happens when it is configured using `DATABASE_URL`. - *Dieter Komendera* + *korbin* + +* Fix error message when trying to create an associated record and the foreign + key is missing. + + Before this fix the following exception was being raised: + + NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218> + + Now the message is: + + ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model. -* `includes` is able to detect the right preloading strategy when string - joins are involved. + *Rafael Mendonça França* - Fixes #14109. +* Fix change detection problem for PostgreSQL bytea type and + `ArgumentError: string contains null byte` exception with pg-0.18. - *Aaron Patterson*, *Yves Senn* + Fixes #17680. -* Fixed error with validation with enum fields for records where the - value for any enum attribute is always evaluated as 0 during - uniqueness validation. + *Lars Kanis* - Fixes #14172. +* When a table has a composite primary key, the `primary_key` method for + SQLite3 and PostgreSQL adapters was only returning the first field of the key. + Ensures that it will return nil instead, as Active Record doesn't support + composite primary keys. - *Vilius Luneckas* *Ahmed AbouElhamayed* + Fixes #18070. + + *arthurnn* + +* `validates_size_of` / `validates_length_of` do not count records + which are `marked_for_destruction?`. + + Fixes #7247. + + *Yves Senn* + +* Ensure `first!` and friends work on loaded associations. + + Fixes #18237. + + *Sean Griffin* -* `before_add` callbacks are fired before the record is saved on - `has_and_belongs_to_many` associations *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. +* `eager_load` preserves readonly flag for associations. - Fixes #14144. + Fixes #15853. -* Fixed STI classes not defining an attribute method if there is a - conflicting private method defined on its ancestors. + *Takashi Kokubun* - Fixes #11569. +* Provide `:touch` option to `save()` to accommodate saving without updating + timestamps. - *Godfrey Chan* + Fixes #18202. -* Coerce strings when reading attributes. Fixes #10485. + *Dan Olson* + +* Provide a more helpful error message when an unsupported class is passed to + `serialize`. + + Fixes #18224. + + *Sean Griffin* + +* Add bigint primary key support for MySQL. Example: - book = Book.new(title: 12345) - book.save! - book.title # => "12345" + create_table :foos, id: :bigint do |t| + end + + *Ryuta Kamizono* + +* Support for any type of primary key. + + Fixes #14194. + + *Ryuta Kamizono* + +* Dump the default `nil` for PostgreSQL UUID primary key. + + *Ryuta Kamizono* + +* Add a `:foreign_key` option to `references` and associated migration + methods. The model and migration generators now use this option, rather than + the `add_foreign_key` form. + + *Sean Griffin* + +* Don't raise when writing an attribute with an out-of-range datetime passed + by the user. + + *Grey Baker* + +* Replace deprecated `ActiveRecord::Tasks::DatabaseTasks#load_schema` with + `ActiveRecord::Tasks::DatabaseTasks#load_schema_for`. *Yves Senn* -* 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. +* Fix bug with `ActiveRecord::Type::Numeric` that caused negative values to + be marked as having changed when set to the same negative value. + + Fixes #18161. + + *Daniel Fox* + +* Introduce `force: :cascade` option for `create_table`. Using this option + will recreate tables even if they have dependent objects (like foreign keys). + `db/schema.rb` now uses `force: :cascade`. This makes it possible to + reload the schema when foreign keys are in place. + + *Matthew Draper*, *Yves Senn* + +* `db:schema:load` and `db:structure:load` no longer purge the database + before loading the schema. This is left for the user to do. + `db:test:prepare` will still purge the database. - 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. + Fixes #17945. *Yves Senn* -* Support for user created range types in PostgreSQL. +* Fix undesirable RangeError by `Type::Integer`. Add `Type::UnsignedInteger`. + + *Ryuta Kamizono* + +* Add `foreign_type` option to `has_one` and `has_many` association macros. + + This option enables to define the column name of associated object's type for polymorphic associations. + + *Ulisses Almeida*, *Kassio Borges* + +* Remove deprecated behavior allowing nested arrays to be passed as query + values. + + *Melanie Gilman* + +* Deprecate passing a class as a value in a query. Users should pass strings + instead. + + *Melanie Gilman* + +* `add_timestamps` and `remove_timestamps` now properly reversible with + options. + + *Noam Gagliardi-Rabinovich* + +* `ActiveRecord::ConnectionAdapters::ColumnDumper#column_spec` and + `ActiveRecord::ConnectionAdapters::ColumnDumper#prepare_column_options` no + longer have a `types` argument. They should access + `connection#native_database_types` directly. *Yves Senn* -Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md) for previous changes. +Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activerecord/CHANGELOG.md) for previous changes. |