diff options
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r-- | activerecord/CHANGELOG.md | 598 |
1 files changed, 146 insertions, 452 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f44f98cdec..d39e808f5b 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,573 +1,267 @@ -* Load fixtures from linked folders. +* Fixed a problem where an enum would overwrite values of another enum + with the same name in an unrelated class. - *Kassio Borges* + Fixes #14607. -* Create a directory for sqlite3 file if not present on the system. + *Evan Whalen* - *Richard Schneeman* +* PostgreSQL and SQLite string columns no longer have a default limit of 255. -* Removed redundant override of `xml` column definition for PG, - in order to use `xml` column type instead of `text`. + Fixes #13435, #9153. - *Paul Nikitochkin*, *Michael Nikitochkin* + *Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn* -* Revert `ActiveRecord::Relation#order` change that make new order - prepend the old one. +* Make possible to have an association called `records`. - Before: + Fixes #11645. - User.order("name asc").order("created_at desc") - # SELECT * FROM users ORDER BY created_at desc, name asc + *prathamesh-sonpatki* - After: +* `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. - User.order("name asc").order("created_at desc") - # SELECT * FROM users ORDER BY name asc, created_at desc + Fixes #14003. - This also affects order defined in `default_scope` or any kind of associations. + *Jefferson Lai* -* Add ability to define how a class is converted to Arel predicates. - For example, adding a very vendor specific regex implementation: +* Block a few default Class methods as scope name. - regex_handler = proc do |column, value| - Arel::Nodes::InfixOperation.new('~', column, value.source) - end - ActiveRecord::PredicateBuilder.register_handler(Regexp, regex_handler) - - *Sean Griffin & @joannecheng* - -* 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* - -* When using optimistic locking, `update` was not passing the column to `quote_value` - to allow the connection adapter to properly determine how to quote the value. This was - affecting certain databases that use specific column types. - - Fixes: #6763 - - *Alfred Wong* - -* rescue from all exceptions in `ConnectionManagement#call` - - Fixes #11497 - - 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* - -* `change_column` for PostgreSQL adapter respects the `:array` option. - - *Yves Senn* - -* Remove deprecation warning from `attribute_missing` for attributes that are columns. - - *Arun Agrawal* + For instance, this will raise: -* Remove extra decrement of transaction deep level. + scope :public, -> { where(status: 1) } - Fixes: #4566 + *arthurnn* - *Paul Nikitochkin* +* Fixed error when using `with_options` with lambda. -* Reset @column_defaults when assigning `locking_column`. - We had a potential problem. For example: + Fixes #9805. - class Post < ActiveRecord::Base - self.column_defaults # if we call this unintentionally before setting locking_column ... - self.locking_column = 'my_locking_column' - end + *Lauro Caetano* - Post.column_defaults["my_locking_column"] - => nil # expected value is 0 ! +* Switch `sqlite3:///` URLs (which were temporarily + deprecated in 4.1) from relative to absolute. - *kennyj* + If you still want the previous interpretation, you should replace + `sqlite3:///my/path` with `sqlite3:my/path`. -* Remove extra select and update queries on save/touch/destroy ActiveRecord model - with belongs to reflection with option `touch: true`. + *Matthew Draper* - Fixes: #11288 +* Treat blank UUID values as `nil`. - *Paul Nikitochkin* + Example: -* Remove deprecated nil-passing to the following `SchemaCache` methods: - `primary_keys`, `tables`, `columns` and `columns_hash`. + Sample.new(uuid_field: '') #=> <Sample id: nil, uuid_field: nil> - *Yves Senn* + *Dmitry Lavrov* -* Remove deprecated block filter from `ActiveRecord::Migrator#migrate`. +* Enable support for materialized views on PostgreSQL >= 9.3. - *Yves Senn* + *Dave Lee* -* Remove deprecated String constructor from `ActiveRecord::Migrator`. +* The PostgreSQL adapter supports custom domains. Fixes #14305. *Yves Senn* -* Remove deprecated `scope` use without passing a callable object. - - *Arun Agrawal* - -* Remove deprecated `transaction_joinable=` in favor of `begin_transaction` - with `:joinable` option. - - *Arun Agrawal* - -* Remove deprecated `decrement_open_transactions`. - - *Arun Agrawal* - -* Remove deprecated `increment_open_transactions`. +* 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`. - *Arun Agrawal* - -* Remove deprecated `PostgreSQLAdapter#outside_transaction?` - method. You can use `#transaction_open?` instead. + See #7814. *Yves Senn* -* Remove deprecated `ActiveRecord::Fixtures.find_table_name` in favor of - `ActiveRecord::Fixtures.default_fixture_model_name`. - - *Vipul A M* - -* Removed deprecated `columns_for_remove` from `SchemaStatements`. - - *Neeraj Singh* - -* Remove deprecated `SchemaStatements#distinct`. - - *Francesco Rodriguez* - -* 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* +* Fixed error when specifying a non-empty default value on a PostgreSQL array column. -* Removed support for deprecated option `:restrict` for `:dependent` - in associations. + Fixes #10613. - *Neeraj Singh* + *Luke Steensen* -* Removed support for deprecated `delete_sql` in associations. +* Make possible to change `record_timestamps` inside Callbacks. - *Neeraj Singh* + *Tieg Zaharia* -* Removed support for deprecated `insert_sql` in associations. +* Fixed error where .persisted? throws SystemStackError for an unsaved model with a + custom primary key that didn't save due to validation error. - *Neeraj Singh* + Fixes #14393. -* Removed support for deprecated `finder_sql` in associations. + *Chris Finne* - *Neeraj Singh* +* Introduce `validate` as an alias for `valid?`. -* Support array as root element in JSON fields. + This is more intuitive when you want to run validations but don't care about the return value. - *Alexey Noskov & Francesco Rodriguez* + *Henrik Nyh* -* Removed support for deprecated `counter_sql` in associations. +* Create indexes inline in CREATE TABLE for MySQL. - *Neeraj Singh* + This is important, because adding an index on a temporary table after it has been created + would commit the transaction. -* Do not invoke callbacks when `delete_all` is called on collection. - - 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 - if `:dependent` value is `:destroy` then the default deletion - strategy for that collection will be applied. - - User can also force a deletion strategy by passing parameter to - `delete_all`. For example you can do `@post.comments.delete_all(:nullify)` . - - *Neeraj Singh* - -* Calling default_scope without a proc will now raise `ArgumentError`. - - *Neeraj Singh* - -* Removed deprecated method `type_cast_code` from Column. - - *Neeraj Singh* - -* Removed deprecated options `delete_sql` and `insert_sql` from HABTM - association. - - Removed deprecated options `finder_sql` and `counter_sql` from - collection association. - - *Neeraj Singh* - -* Remove deprecated `ActiveRecord::Base#connection` method. - Make sure to access it via the class. - - *Yves Senn* - -* Remove deprecation warning for `auto_explain_threshold_in_seconds`. - - *Yves Senn* - -* Remove deprecated `:distinct` option from `Relation#count`. - - *Yves Senn* - -* Removed deprecated methods `partial_updates`, `partial_updates?` and - `partial_updates=`. - - *Neeraj Singh* - -* Removed deprecated method `scoped` - - *Neeraj Singh* - -* Removed deprecated method `default_scopes?` - - *Neeraj Singh* - -* Remove implicit join references that were deprecated in 4.0. + It also allows creating and dropping indexed tables with fewer queries and fewer permissions + required. Example: - # before with implicit joins - Comment.where('posts.author_id' => 7) - - # after - Comment.references(:posts).where('posts.author_id' => 7) - - *Yves Senn* - -* Apply default scope when joining associations. For example: - - class Post < ActiveRecord::Base - default_scope -> { where published: true } + 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 - 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* + *Cody Cutrer*, *Steve Rice*, *Rafael Mendonça Franca* -* Remove `activerecord-deprecated_finders` as a dependency +* Save `has_one` association even if the record doesn't changed. - *Łukasz Strzałkowski* + Fixes #14407. -* Remove Oracle / Sqlserver / Firebird database tasks that were deprecated in 4.0. + *Rafael Mendonça França* - *kennyj* +* Use singular table name in generated migrations when + `ActiveRecord::Base.pluralize_table_names` is `false`. -* `find_each` now returns an `Enumerator` when called without a block, so that it - can be chained with other `Enumerable` methods. + Fixes #13426. - *Ben Woosley* + *Kuldeep Aggarwal* -* `ActiveRecord::Result.each` now returns an `Enumerator` when called without - a block, so that it can be chained with other `Enumerable` methods. - - *Ben Woosley* - -* Flatten merged join_values before building the joins. - - 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* - -* 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* - -* `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. +* `touch` accepts many attributes to be touched at once. Example: - Author.inspect # => "Author(no database connection)" - - *Yves Senn* - -* Handle single quotes in PostgreSQL default column values. - Fixes #10881. - - *Dylan Markow* - -* 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'`. + # touches :signed_at, :sealed_at, and :updated_at/on attributes. + Photo.last.touch(:signed_at, :sealed_at) - Do not squeeze whitespace out of sql queries. Fixes #10982. + *James Pinto* - *Neeraj Singh* +* `rake db:structure:dump` only dumps schema information if the schema + migration table exists. -* Fixture setup does no longer depend on `ActiveRecord::Base.configurations`. - This is relevant when `ENV["DATABASE_URL"]` is used in place of a `database.yml`. + Fixes #14217. *Yves Senn* -* Fix mysql2 adapter raises the correct exception when executing a query on a - closed connection. +* 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. - *Yves Senn* - -* Ambiguous reflections are on :through relationships are no longer supported. - For example, you need to change this: - - class Author < ActiveRecord::Base - has_many :posts - has_many :taggings, :through => :posts - end - - class Post < ActiveRecord::Base - has_one :tagging - has_many :taggings - end - - class Tagging < ActiveRecord::Base - end - - To this: + *Matthew Draper* - class Author < ActiveRecord::Base - has_many :posts - has_many :taggings, :through => :posts, :source => :tagging - end +* `pk_and_sequence_for` now ensures that only the pg_depend entries + pointing to pg_class, and thus only sequence objects, are considered. - class Post < ActiveRecord::Base - has_one :tagging - has_many :taggings - end + *Josh Williams* - class Tagging < ActiveRecord::Base - end +* `where.not` adds `references` for `includes` like normal `where` calls do. - *Aaron Patterson* - -* Remove column restrictions for `count`, let the database raise if the SQL is - invalid. The previous behavior was untested and surprising for the user. - 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 + Fixes #14406. *Yves Senn* -* 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: - - class Taggable < ActiveRecord::Base - belongs_to :tag, inverse_of: false - end - - *John Wang* - -* Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432 - - *Adam Anderson* - -* Usage of `implicit_readonly` is being removed`. Please use `readonly` method - explicitly to mark records as `readonly. - Fixes #10615. +* Extend fixture `$LABEL` replacement to allow string interpolation. 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* - -* Fix the `:primary_key` option for `has_many` associations. - Fixes #10693. - - *Yves Senn* - -* Fix bug where tiny types are incorrectly coerced as boolean when the length is more than 1. - - Fixes #10620. - - *Aaron Patterson* - -* Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1. - - *kennyj* + martin: + email: $LABEL@email.com -* Deprecate `ConnectionAdapters::SchemaStatements#distinct`, - as it is no longer used by internals. + users(:martin).email # => martin@email.com - *Ben Woosley* + *Eric Steele* -* Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix` - is not blank. +* Add support for `Relation` be passed as parameter on `QueryCache#select_all`. - Call `assume_migrated_upto_version` on connection to prevent it from first - being picked up in `method_missing`. + Fixes #14361. - 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`. + *arthurnn* - Fixes #10411. +* Passing an Active Record object to `find` is now deprecated. Call `.id` + on the object first. - *Kyle Stevens* +* Passing an Active Record object to `find` or `exists?` is now deprecated. + Call `.id` on the object first. -* Method `read_attribute_before_type_cast` should accept input as symbol. +* Only use BINARY for MySQL case sensitive uniqueness check when column has a case insensitive collation. - *Neeraj Singh* + *Ryuta Kamizono* -* Confirm a record has not already been destroyed before decrementing counter cache. +* Support for MySQL 5.6 fractional seconds. - *Ben Tucker* + *arthurnn*, *Tatsuhiko Miyagawa* -* 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`. +* Support for Postgres `citext` data type enabling case-insensitive where + values without needing to wrap in UPPER/LOWER sql functions. - *Zach Ohlgren* + *Troy Kruthoff*, *Lachlan Sylvester* -* While removing index if column option is missing then raise IrreversibleMigration exception. +* Allow strings to specify the `#order` value. - 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* - -* 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 + Example: - member = Member.new - member.avatar_attributes = {icon: 'sad'} - member.avatar.width # => 200 + Model.order(id: 'asc').to_sql == Model.order(id: :asc).to_sql - *Olek Janiszewski* + *Marcelo Casiraghi*, *Robin Dupret* -* 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. +* Dynamically register PostgreSQL enum OIDs. This prevents "unknown OID" + warnings on enum columns. - *Johnny Holton* + *Dieter Komendera* -* Handle aliased attributes in ActiveRecord::Relation. +* `includes` is able to detect the right preloading strategy when string + joins are involved. - When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database: + Fixes #14109. - With the model + *Aaron Patterson*, *Yves Senn* - class Topic - alias_attribute :heading, :title - end +* Fixed error with validation with enum fields for records where the + value for any enum attribute is always evaluated as 0 during + uniqueness validation. - The call + Fixes #14172. - Topic.where(heading: 'The First Topic') + *Vilius Luneckas* *Ahmed AbouElhamayed* - should yield the same result as +* `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. - Topic.where(title: 'The First Topic') + Fixes #14144. - This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`. +* Fixed STI classes not defining an attribute method if there is a + conflicting private method defined on its ancestors. - This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`. + Fixes #11569. *Godfrey Chan* -* Mute `psql` output when running rake db:schema:load. +* Coerce strings when reading attributes. Fixes #10485. - *Godfrey Chan* + Example: -* Trigger a save on `has_one association=(associate)` when the associate contents have changed. + book = Book.new(title: 12345) + book.save! + book.title # => "12345" - Fix #8856. + *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. |