aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/CHANGELOG.md
Commit message (Collapse)AuthorAgeFilesLines
* Add #create_or_find_by to lean on unique constraints (#31989)David Heinemeier Hansson2018-02-141-0/+6
| | | Add #create_or_find_by to lean on unique constraints
* Start Rails 6.0 development!!!Rafael Mendonça França2018-01-301-667/+1
| | | | :tada::tada::tada:
* Deprecate `expand_hash_conditions_for_aggregates`Ryuta Kamizono2018-01-291-0/+5
| | | | | This can not expand an array of aggregated objects correctly, and is no longer used internally since 159b21b5.
* Merge pull request #31724 from orekyuu/fix-expand-composed-object-arrayRyuta Kamizono2018-01-291-0/+14
|\ | | | | | | Fix not expanded problem when passing an Array object as argument to the where method using composed_of column.
| * Fix not expanded problem when passing an Array object as argument to the ↵orekyuu2018-01-261-0/+14
|/ | | | | | | | | | | | | | where method using composed_of column. Fixes #31723 ``` david_balance = customers(:david).balance Customer.where(balance: [david_balance]).to_sql # Before: WHERE `customers`.`balance` = NULL # After : WHERE `customers`.`balance` = 50 ```
* Fix `count(:all)` with eager loading and having an order other than the ↵Ryuta Kamizono2018-01-251-0/+6
| | | | | | | | | | | | | | | | | | | driving table This is a regression caused by 6beb4de. In PostgreSQL, ORDER BY expressions must appear in SELECT list when using DISTINCT. When using `count(:all)` with eager loading, Active Record enforces DISTINCT to count the driving table records only. 6beb4de was caused the regression because `count(:all)` with DISTINCT path no longer removes ORDER BY. We need to ignore ORDER BY when DISTINCT is enforced, otherwise not always generated valid SQL for PostgreSQL. Fixes #31783.
* Expand AR to Active Record [ci skip]Ryuta Kamizono2018-01-251-2/+2
|
* Clear the transaction state when AR object is dupedYuriy Ustushenko2018-01-251-0/+6
|
* Support for PostgreSQL foreign tablesfatkodima2018-01-221-0/+4
|
* Fix relation merger issue with `left_outer_joins`Mehmet Emin INAC2018-01-151-0/+4
|
* Don't allow destroyed object mutation after `save` or `save!` is calledRyuta Kamizono2018-01-151-0/+4
| | | | | | | | | | Currently `object.save` will unfreeze the object, due to `changes_applied` replaces frozen `@attributes` to new `@attributes`. Since originally destroyed objects are not allowed to be mutated, `save` and `save!` should not return success in that case. Fixes #28563.
* Merge pull request #23146 from piotrj/issue_18424Ryuta Kamizono2018-01-111-0/+6
|\ | | | | | | When deleting through records, take into account association conditions
* \ Merge pull request #16314 from ↵Ryuta Kamizono2018-01-101-0/+38
|\ \ | | | | | | | | | | | | | | | zoltankiss/allow-nested-has-many-associations-on-unpersisted-parent-instances fix nested `has many :through` associations on unpersisted parent instances
* | | resolve inconsistencies between first and to_a.first with limitBrian Christian2018-01-091-0/+8
| | |
* | | Merge pull request #27561 from fishbrain/count-all-in-has-many-associationRyuta Kamizono2018-01-031-0/+5
|\ \ \ | | | | | | | | | | | | Use `count(:all)` in HasManyAssociation#count_records
| * | | Use `count(:all)` in HasManyAssociation#count_recordsKlas Eskilson2017-02-071-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Calling `count` on an association can cause invalid SQL queries to be created where the `SELECT COUNT(a, b, c)` function receives multiple columns. This will cause a `StatementInvalid` exception later on. Solution: Use `count(:all)`, which generates a `SELECT COUNT(*)...` query independently of the association. This also includes a test case that, before the fix, broke.
* | | | Merge pull request #27780 from ↵Ryuta Kamizono2017-12-251-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | mikelikesbikes/fix-update-attribute-callbacks-issue save attributes changed by callbacks after update_attribute
* | | | Remove verbose_query_logs from new_framework_defaults_5_2.rbEugene Kenny2017-12-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `app:update` rake task will regenerate `development.rb` so that it contains this option; that means we're currently adding it to existing apps in two places, which is unnecessary and confusing. Also: - Remove inaccurate comment about which stack frames are ignored - Clarify that the feature uses `caller_locations`, not `caller` - Remove unused return value in `extract_callstack`
* | | | Fix `count(:all)` to correctly work `distinct` with custom SELECT listRyuta Kamizono2017-12-201-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently `count(:all)` with `distinct` doesn't work correctly because SELECT list is always replaced to `*` or primary key in that case even if having custom SELECT list. And also, PostgreSQL has a limitation that ORDER BY expressions must appear in select list for SELECT DISTINCT. Therefore, we should not replace custom SELECT list when using `count(:all)` with `distinct`. Closes #31277.
* | | | Using subselect for `delete_all` with `limit` or `offset`Ryuta Kamizono2017-12-191-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | Arel doesn't support subselect generation for DELETE unlike UPDATE yet, but we already have that generation in connection adapters. We can simply use the subselect generated by that one.
* | | | Add changelog entry for e1ceb10Chris Salzberg2017-12-171-0/+5
| | | |
* | | | Log call site for all queriesOlivier Lacan2017-12-131-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new ActiveRecord configuration option allows you to easily pinpoint what line of application code is triggering SQL queries in the development log by appending below each SQL statement log the line of Ruby code that triggered it. It’s useful with N+1 issues, and to locate stray queries. By default this new option ignores Rails and Ruby code in order to surface only callers from your application Ruby code or your gems. It is enabled on newly generated Rails 5.2 applications and can be enabled on existing Rails applications: ```ruby Rails.application.configure do # ... config.active_record.verbose_query_logs = true end ``` The `rails app:upgrade` task will also add it to `config/development.rb`. This feature purposely avoids coupling with ActiveSupport::BacktraceCleaner since ActiveRecord can be used without ActiveRecord. This decision can be reverted in the future to allow more configurable backtraces (the exclusion of gem callers for example).
* | | | Fix conflicts `counter_cache` with `touch: true` by optimistic locking.bogdanvlviv2017-12-121-0/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` # create_table :posts do |t| # t.integer :comments_count, default: 0 # t.integer :lock_version # t.timestamps # end class Post < ApplicationRecord end # create_table :comments do |t| # t.belongs_to :post # end class Comment < ApplicationRecord belongs_to :post, touch: true, counter_cache: true end ``` Before: ``` post = Post.create! # => begin transaction INSERT INTO "posts" ("created_at", "updated_at", "lock_version") VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0) commit transaction comment = Comment.create!(post: post) # => begin transaction INSERT INTO "comments" ("post_id") VALUES (1) UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1, "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1 UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330', "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0 rollback transaction # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post. Comment.take.destroy! # => begin transaction DELETE FROM "comments" WHERE "comments"."id" = 1 UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1, "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1 UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901', "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0 rollback transaction # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post. ``` After: ``` post = Post.create! # => begin transaction INSERT INTO "posts" ("created_at", "updated_at", "lock_version") VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0) commit transaction comment = Comment.create!(post: post) # => begin transaction INSERT INTO "comments" ("post_id") VALUES (1) UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1, "lock_version" = COALESCE("lock_version", 0) + 1, "updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1 commit transaction comment.destroy! # => begin transaction DELETE FROM "comments" WHERE "comments"."id" = 1 UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1, "lock_version" = COALESCE("lock_version", 0) + 1, "updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1 commit transaction ``` Fixes #31199.
* | | | Tweaks CHANGELOGs [ci skip]Ryuta Kamizono2017-12-011-2/+2
| | | |
* | | | Add support for PostgreSQL operator classes to add_indexGreg Navis2017-11-301-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for specifying non-default operator classes in PostgreSQL indexes. An example CREATE INDEX query that becomes possible is: CREATE INDEX users_name ON users USING gist (name gist_trgm_ops); Previously it was possible to specify the `gist` index but not the custom operator class. The `add_index` call for the above query is: add_index :users, :name, using: :gist, opclasses: {name: :gist_trgm_ops}
* | | | Merge pull request #31179 from kinnrot/scoping-reserved-namesRafael Mendonça França2017-11-281-0/+7
|\ \ \ \ | | | | | | | | | | | | | | | Scoping reserved names
| * | | | Prevent scope named same as a ActiveRecord::Relation instance method.Chen Kinnrot2017-11-281-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to inconsistent behavior when chaining scopes and one scope named after a Relation method Validation code added in 2 places: - scope, to prevent problematic scope names. - enum, cause it tries to auto define scope.
* | | | | Preparing for 5.2.0.beta2 releaseRafael Mendonça França2017-11-281-0/+5
|/ / / /
* | | | Preparing for 5.2.0.beta1 releaseRafael Mendonça França2017-11-271-0/+2
| | | |
* | | | Add new error class `QueryCanceled` which will be raised when canceling ↵Ryuta Kamizono2017-11-271-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | statement due to user request (#31235) This changes `StatementTimeout` to `QueryCanceled` for PostgreSQL. In MySQL, errno 1317 (`ER_QUERY_INTERRUPTED`) is only used when the query is manually cancelled. But in PostgreSQL, `QUERY_CANCELED` error code (57014) which is used `StatementTimeout` is also used when the both case. And, we can not tell which reason happened. So I decided to introduce new error class `QueryCanceled` closer to the error code name.
* | | | Rename `TransactionTimeout` to more descriptive `LockWaitTimeout` (#31223)Ryuta Kamizono2017-11-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Since #31129, new error class `StatementTimeout` has been added. `TransactionTimeout` is caused by the timeout shorter than `StatementTimeout`, but its name is too generic. I think that it should be a name that understands the difference with `StatementTimeout`.
* | | | Fix typo s/only_up/up_only/ [ci skip]Ryuta Kamizono2017-11-151-1/+1
| | | |
* | | | Add a #populate method to migrations (#31082)Rich2017-11-141-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add a #populate method to migrations * Address rubocop issues * Rename to #up_only and use #execute in the examples intead of the model * Update CHANGELOG [Rich Daley & Rafael Mendonça França]
* | | | Merge pull request #27947 from mastahyeti/unsafe_raw_sqlMatthew Draper2017-11-141-0/+30
|\ \ \ \ | | | | | | | | | | | | | | | Disallow raw SQL in dangerous AR methods
* | | | | Properly cast input in `update_all`Sean Griffin2017-11-131-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The documentation claims that given values go through "normal AR type casting and serialization", which to me implies `serialize(cast(value))`, not just serialization. The docs were changed to use this wording in #22492. The tests I cited in that PR (which is the same test modified in this commit), is worded in a way that implies it should be using `cast` as well. It's possible that I originally meant "normal type casting" to imply just the call to `serialize`, but given that `update_all(archived: params['archived'])` seems to be pretty common, I'm inclined to make this change as long as no tests are broken from it.
* | | | | Add new error class `StatementTimeout` which will be raised when statement ↵Ryuta Kamizono2017-11-131-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | timeout exceeded (#31129) We are sometimes using The MAX_EXECUTION_TIME hint for MySQL depending on the situation. It will prevent catastrophic performance down by wrong performing queries. The new error class `StatementTimeout` will make to be easier to handle that case. https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html#optimizer-hints-execution-time
* | | | | Raise `TransactionTimeout` when lock wait timeout exceeded for PG adapterRyuta Kamizono2017-11-111-2/+2
|/ / / / | | | | | | | | | | | | Follow up of #30360.
* | | | Fix `bin/rails db:migrate` with specified `VERSION`bogdanvlviv2017-11-061-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | Ensure that `bin/rails db:migrate` with specified `VERSION` reverts all migrations only if `VERSION` is `0`. Raise error if target migration doesn't exist.
* | | | Remove CHANGELOG entry for PR #28681 [ci skip]Prathamesh Sonpatki2017-10-271-4/+0
| | | | | | | | | | | | | | | | | | | | - It is present in Rails 5.1.3 already. - Backport commit https://github.com/rails/rails/commit/9efa0b70a638dcfdc05b30ab530f89f2847bb9c2
* | | | Save index order :desc to schema.rb (sqlite). Fixes #30902Paul Kuruvilla2017-10-241-0/+7
| | | | | | | | | | | | | | | | | | | | Although the sqlite adapter supports index sort orders, they weren't being written to db/schema.rb.
* | | | Remove deprecated method `#sanitize_conditions`Rafael Mendonça França2017-10-231-0/+4
| | | |
* | | | Remove deprecated methd `#scope_chain`Rafael Mendonça França2017-10-231-0/+4
| | | |
* | | | Remove deprecated configuration `.error_on_ignored_order_or_limit`Rafael Mendonça França2017-10-231-0/+4
| | | |
* | | | Remove deprecated arguments from `#verify!`Rafael Mendonça França2017-10-231-0/+4
| | | |
* | | | Remove deprecated argument `name` from `#indexes`Rafael Mendonça França2017-10-231-0/+4
| | | |
* | | | Remove deprecated method `ActiveRecord::Migrator.schema_migrations_table_name`Rafael Mendonça França2017-10-231-0/+4
| | | |
* | | | Remove deprecated method `supports_primary_key?`Rafael Mendonça França2017-10-231-0/+4
| | | |
* | | | Remove deprecated method `supports_migrations?`Rafael Mendonça França2017-10-231-0/+4
| | | |
* | | | Remove deprecated methods `initialize_schema_migrations_table` and ↵Rafael Mendonça França2017-10-231-0/+4
| | | | | | | | | | | | | | | | `initialize_internal_metadata_table`
* | | | Rase when calling `lock!` in a dirty recordRafael Mendonça França2017-10-231-0/+4
| | | |