diff options
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r-- | activerecord/CHANGELOG.md | 594 |
1 files changed, 508 insertions, 86 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f5038a2ad0..cf85ec637a 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -3,153 +3,575 @@ *Joao Carlos* -* Usage of `implicit_readonly` is being removed`. Please use `readonly` method - explicitly to mark records as `readonly. - Fixes #10615. +* The `:index` option in migrations, which previously was only available for + `references`, now works with any column types. - Example: + *Marc Schütz* + +* Add support for counter name to be passed as parameter on `CounterCache::ClassMethods#reset_counters`. + + *jnormore* + +* Restrict deletion of record when using `delete_all` with `uniq`, `group`, `having` + or `offset`. + + In these cases the generated query ignored them and that caused unintended + records to be deleted. + + Fixes #11985. + + *Leandro Facchinetti* + +* Floats with limit >= 25 that get turned into doubles in MySQL no longer have + their limit dropped from the schema. + + Fixes #14135. + + *Aaron Nelson* + +* Fix how to calculate associated class name when using namespaced `has_and_belongs_to_many` + association. + + Fixes #14709. + + *Kassio Borges* - user = User.joins(:todos).select("users.*, todos.title as todos_title").readonly(true).first - user.todos_title = 'clean pet' - user.save! # will raise error +* `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and + strings in column names as equal. + + This fixes a rare case in which more bind values are passed than there are + placeholders for them in the generated SQL statement, which can make PostgreSQL + throw a `StatementInvalid` exception. + + *Nat Budin* + +* Fix `stored_attributes` to correctly merge the details of stored + attributes defined in parent classes. + + Fixes #14672. + + *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy* + +* `change_column_default` allows `[]` as argument to `change_column_default`. + + Fixes #11586. *Yves Senn* -* Fix the `:primary_key` option for `has_many` associations. - Fixes #10693. +* Handle `name` and `"char"` column types in the PostgreSQL adapter. + + `name` and `"char"` are special character types used internally by + PostgreSQL and are used by internal system catalogs. These field types + can sometimes show up in structure-sniffing queries that feature internal system + structures or with certain PostgreSQL extensions. + + *J Smith*, *Yves Senn* + +* Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and + NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN` + + Before: + + Point.create(value: 1.0/0) + Point.last.value # => 0.0 + + After: + + Point.create(value: 1.0/0) + Point.last.value # => Infinity + + *Innokenty Mikhailov* + +* Allow the PostgreSQL adapter to handle bigserial pk types again. + + Fixes #10410. + + *Patrick Robertson* + +* Deprecate joining, eager loading and preloading of instance dependent + associations without replacement. These operations happen before instances + are created. The current behavior is unexpected and can result in broken + behavior. + + Fixes #15024. *Yves Senn* -* Fix bug where tiny types are incorectly coerced as booleand when the length is more than 1. +* Fixed HABTM's CollectionAssociation size calculation. - Fixes #10620. + HABTM should fall back to using the normal CollectionAssociation's size + calculation if the collection is not cached or loaded. - *Aaron Peterson* + Fixes #14913, #14914. -* Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1. + *Fred Wu* - *kennyj* +* Return a non zero status when running `rake db:migrate:status` and migration table does + not exist. -* Deprecate `ConnectionAdapters::SchemaStatements#distinct`, - as it is no longer used by internals. + *Paul B.* - *Ben Woosley# +* Add support for module-level `table_name_suffix` in models. -* Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix` - is not blank. + This makes `table_name_suffix` work the same way as `table_name_prefix` when + using namespaced models. - Call `assume_migrated_upto_version` on connection to prevent it from first - being picked up in `method_missing`. + *Jenner LaFave* - 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`. +* Revert the behaviour of `ActiveRecord::Relation#join` changed through 4.0 => 4.1 to 4.0. - Fixes #10411. + In 4.1.0 `Relation#join` is delegated to `Arel#SelectManager`. + In 4.0 series it is delegated to `Array#join`. - *Kyle Stevens* + *Bogdan Gusiev* -* Method `read_attribute_before_type_cast` should accept input as symbol. +* Log nil binary column values correctly. - *Neeraj Singh* + 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. -* Confirm a record has not already been destroyed before decrementing counter cache. + *James Coleman* - *Ben Tucker* +* Rails will now pass a custom validation context through to autosave associations + in order to validate child associations with the same context. -* Fixed a bug in `ActiveRecord#sanitize_sql_hash_for_conditions` in which - `self.class` is an argument to `PredicateBuilder#build_from_hash` - causing `PredicateBuilder` to call non-existent method - `Class#reflect_on_association`. + Fixes #13854. - *Zach Ohlgren* + *Eric Chahin*, *Aaron Nelson*, *Kevin Casey* -* While removing index if column option is missing then raise IrreversibleMigration exception. +* Stringify all variable keys of mysql connection configuration. - Following code should raise `IrreversibleMigration`. But the code was - failing since options is an array and not a hash. + When the `sql_mode` variable for mysql adapters is set in the configuration + as a `String`, it was ignored and overwritten by the strict mode option. - def change - change_table :users do |t| - t.remove_index [:name, :email] - end - end + Fixes #14895. + + *Paul Nikitochkin* + +* Ensure SQLite3 statements are closed on errors. + + Fixes #13631. + + *Timur Alperovich* + +* Give ActiveRecord::PredicateBuilder private methods the privacy they deserve. + + *Hector Satre* + +* When using a custom `join_table` name on a `habtm`, rails was not saving it + on Reflections. This causes a problem when rails loads fixtures, because it + uses the reflections to set database with fixtures. + + Fixes #14845. + + *Kassio Borges* + +* Reset the cache when modifying a Relation with cached Arel. + Additionally display a warning message to make the user aware. + + *Yves Senn* + +* PostgreSQL should internally use `:datetime` consistently for TimeStamp. Assures + different spellings of timestamps are treated the same. + + Example: + + mytimestamp.simplified_type('timestamp without time zone') + # => :datetime + mytimestamp.simplified_type('timestamp(6) without time zone') + # => also :datetime (previously would be :timestamp) - Fix was to check if the options is a Hash before operating on it. + See #14513. - Fixes #10419. + *Jefferson Lai* - *Neeraj Singh* +* `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions. -* Do not overwrite manually built records during one-to-one nested attribute assignment + Fixes #14841. - 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.: + *Lucas Mazza* - class Member < ActiveRecord::Base - has_one :avatar - accepts_nested_attributes_for :avatar +* Fix name collision with `Array#select!` with `Relation#select!`. - def avatar - super || build_avatar(width: 200) + Fixes #14752. + + *Earl St Sauver* + +* Fixed unexpected behavior for `has_many :through` associations going through a scoped `has_many`. + + If a `has_many` association is adjusted using a scope, and another `has_many :through` + uses this association, then the scope adjustment is unexpectedly neglected. + + Fixes #14537. + + *Jan Habermann* + +* `@destroyed` should always be set to `false` when an object is duped. + + *Kuldeep Aggarwal* + +* Fixed has_many association to make it support irregular inflections. + + Fixes #8928. + + *arthurnn*, *Javier Goizueta* + +* Fixed a problem where count used with a grouping was not returning a Hash. + + Fixes #14721. + + *Eric Chahin* + +* `sanitize_sql_like` helper method to escape a string for safe use in a SQL + LIKE statement. + + Example: + + class Article + def self.search(term) + where("title LIKE ?", sanitize_sql_like(term)) end end - member = Member.new - member.avatar_attributes = {icon: 'sad'} - member.avatar.width # => 200 + Article.search("20% _reduction_") + # => Query looks like "... title LIKE '20\% \_reduction\_' ..." + + *Rob Gilson*, *Yves Senn* + +* Do not quote uuid default value on `change_column`. + + Fixes #14604. + + *Eric Chahin* + +* The comparison between `Relation` and `CollectionProxy` should be consistent. + + Example: + + author.posts == Post.where(author_id: author.id) + # => true + Post.where(author_id: author.id) == author.posts + # => true + + Fixes #13506. + + *Lauro Caetano* + +* Calling `delete_all` on an unloaded `CollectionProxy` no longer + generates a SQL statement containing each id of the collection: + + Before: + + DELETE FROM `model` WHERE `model`.`parent_id` = 1 + AND `model`.`id` IN (1, 2, 3...) + + After: + + DELETE FROM `model` WHERE `model`.`parent_id` = 1 + + *Eileen M. Uchitelle*, *Aaron Patterson* + +* Fixed error for aggregate methods (`empty?`, `any?`, `count`) with `select` + which created invalid SQL. + + Fixes #13648. + + *Simon Woker* + +* PostgreSQL adapter only warns once for every missing OID per connection. + + Fixes #14275. + + *Matthew Draper*, *Yves Senn* + +* PostgreSQL adapter automatically reloads it's type map when encountering + unknown OIDs. + + Fixes #14678. + + *Matthew Draper*, *Yves Senn* + +* Fix insertion of records via `has_many :through` association with scope. + + Fixes #3548. + + *Ivan Antropov* + +* Auto-generate stable fixture UUIDs on PostgreSQL. + + Fixes #11524. + + *Roderick van Domburg* + +* Fixed a problem where an enum would overwrite values of another enum + with the same name in an unrelated class. + + Fixes #14607. - *Olek Janiszewski* + *Evan Whalen* -* fixes bug introduced by #3329. Now, when autosaving associations, - deletions happen before inserts and saves. This prevents a 'duplicate - 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. +* PostgreSQL and SQLite string columns no longer have a default limit of 255. - *Johnny Holton* + Fixes #13435, #9153. -* Handle aliased attributes in ActiveRecord::Relation. + *Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn* - When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database: +* Make possible to have an association called `records`. - With the model + Fixes #11645. - class Topic - alias_attribute :heading, :title + *prathamesh-sonpatki* + +* `to_sql` on an association now matches the query that is actually executed, where it + could previously have incorrectly accrued additional conditions (e.g. as a result of + a previous query). CollectionProxy now always defers to the association scope's + `arel` method so the (incorrect) inherited one should be entirely concealed. + + Fixes #14003. + + *Jefferson Lai* + +* Block a few default Class methods as scope name. + + For instance, this will raise: + + scope :public, -> { where(status: 1) } + + *arthurnn* + +* Fixed error when using `with_options` with lambda. + + Fixes #9805. + + *Lauro Caetano* + +* Switch `sqlite3:///` URLs (which were temporarily + deprecated in 4.1) from relative to absolute. + + If you still want the previous interpretation, you should replace + `sqlite3:///my/path` with `sqlite3:my/path`. + + *Matthew Draper* + +* Treat blank UUID values as `nil`. + + Example: + + Sample.new(uuid_field: '') #=> <Sample id: nil, uuid_field: nil> + + *Dmitry Lavrov* + +* Enable support for materialized views on PostgreSQL >= 9.3. + + *Dave Lee* + +* The PostgreSQL adapter supports custom domains. Fixes #14305. + + *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`. + + See #7814. + + *Yves Senn* + +* Fixed error when specifying a non-empty default value on a PostgreSQL array column. + + Fixes #10613. + + *Luke Steensen* + +* Make possible to change `record_timestamps` inside Callbacks. + + *Tieg Zaharia* + +* Fixed error where .persisted? throws SystemStackError for an unsaved model with a + custom primary key that didn't save due to validation error. + + Fixes #14393. + + *Chris Finne* + +* Introduce `validate` as an alias for `valid?`. + + This is more intuitive when you want to run validations but don't care about the return value. + + *Henrik Nyh* + +* Create indexes inline in CREATE TABLE for MySQL. + + This is important, because adding an index on a temporary table after it has been created + would commit the transaction. + + It also allows creating and dropping indexed tables with fewer queries and fewer permissions + required. + + Example: + + create_table :temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query" do |t| + t.index :zip end + # => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query - The call + *Cody Cutrer*, *Steve Rice*, *Rafael Mendonça Franca* - Topic.where(heading: 'The First Topic') +* Save `has_one` association even if the record doesn't changed. - should yield the same result as + Fixes #14407. - Topic.where(title: 'The First Topic') + *Rafael Mendonça França* - This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`. +* Use singular table name in generated migrations when + `ActiveRecord::Base.pluralize_table_names` is `false`. - This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`. + Fixes #13426. - *Godfrey Chan* + *Kuldeep Aggarwal* + +* `touch` accepts many attributes to be touched at once. + + Example: + + # touches :signed_at, :sealed_at, and :updated_at/on attributes. + Photo.last.touch(:signed_at, :sealed_at) + + *James Pinto* + +* `rake db:structure:dump` only dumps schema information if the schema + migration table exists. -* Mute `psql` output when running rake db:schema:load. + Fixes #14217. + + *Yves Senn* + +* Reap connections that were checked out by now-dead threads, instead + of waiting until they disconnect by themselves. Before this change, + a suitably constructed series of short-lived threads could starve + the connection pool, without ever having more than a couple alive at + the same time. + + *Matthew Draper* + +* `pk_and_sequence_for` now ensures that only the pg_depend entries + pointing to pg_class, and thus only sequence objects, are considered. + + *Josh Williams* + +* `where.not` adds `references` for `includes` like normal `where` calls do. + + Fixes #14406. + + *Yves Senn* + +* Extend fixture `$LABEL` replacement to allow string interpolation. + + Example: + + martin: + email: $LABEL@email.com + + users(:martin).email # => martin@email.com + + *Eric Steele* + +* Add support for `Relation` be passed as parameter on `QueryCache#select_all`. + + Fixes #14361. + + *arthurnn* + +* Passing an Active Record object to `find` is now deprecated. Call `.id` + on the object first. + +* Passing an Active Record object to `find` or `exists?` is now deprecated. + Call `.id` on the object first. + +* Only use BINARY for MySQL case sensitive uniqueness check when column has a case insensitive collation. + + *Ryuta Kamizono* + +* Support for MySQL 5.6 fractional seconds. + + *arthurnn*, *Tatsuhiko Miyagawa* + +* Support for Postgres `citext` data type enabling case-insensitive where + values without needing to wrap in UPPER/LOWER sql functions. + + *Troy Kruthoff*, *Lachlan Sylvester* + +* Allow strings to specify the `#order` value. + + Example: + + Model.order(id: 'asc').to_sql == Model.order(id: :asc).to_sql + + *Marcelo Casiraghi*, *Robin Dupret* + +* Dynamically register PostgreSQL enum OIDs. This prevents "unknown OID" + warnings on enum columns. + + *Dieter Komendera* + +* `includes` is able to detect the right preloading strategy when string + joins are involved. + + Fixes #14109. + + *Aaron Patterson*, *Yves Senn* + +* Fixed error with validation with enum fields for records where the + value for any enum attribute is always evaluated as 0 during + uniqueness validation. + + Fixes #14172. + + *Vilius Luneckas* *Ahmed AbouElhamayed* + +* `before_add` callbacks are fired before the record is saved on + `has_and_belongs_to_many` assocations *and* on `has_many :through` + associations. Before this change, `before_add` callbacks would be fired + before the record was saved on `has_and_belongs_to_many` associations, but + *not* on `has_many :through` associations. + + Fixes #14144. + +* Fixed STI classes not defining an attribute method if there is a + conflicting private method defined on its ancestors. + + Fixes #11569. *Godfrey Chan* -* Trigger a save on `has_one association=(associate)` when the associate contents have changed. +* Coerce strings when reading attributes. Fixes #10485. - Fix #8856. + Example: + + book = Book.new(title: 12345) + book.save! + book.title # => "12345" + + *Yves Senn* - *Chris Thompson* +* 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. -* Abort a rake task when missing db/structure.sql like `db:schema:load` task. + 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. - *kennyj* + *Yves Senn* -* rake:db:test:prepare falls back to original environment after execution. +* Support for user created range types in PostgreSQL. - *Slava Markevich* + *Yves Senn* -Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md) for previous changes. +Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md) for previous changes. |