aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
Commit message (Collapse)AuthorAgeFilesLines
* Use placeholder for `type_condition` predicateRyuta Kamizono2019-02-181-1/+1
| | | | | | | | | | | | | | Before: ``` SELECT "comments".* FROM "comments" WHERE "comments"."type" IN ('VerySpecialComment') AND "comments"."post_id" = ? LIMIT ? [["post_id", 4], ["LIMIT", 1]] ``` After: ``` SELECT "comments".* FROM "comments" WHERE "comments"."type" = ? AND "comments"."post_id" = ? LIMIT ? [["type", "VerySpecialComment"], ["post_id", 4], ["LIMIT", 1]] ```
* Fix eager loading polymorphic association with mixed table conditionsRyuta Kamizono2019-02-186-26/+43
| | | | | | This fixes a bug that the `foreign_key` and the `foreign_type` are separated as different table conditions if a polymorphic association has a scope that joins another tables.
* Merge pull request #35274 from AlexBrodianoi/fix_does_not_support_reverseRyuta Kamizono2019-02-172-1/+10
|\ | | | | Raise ActiveRecord::IrreversibleOrderError if nulls first/last is not a single ordering argument.
| * Raise ActiveRecord::IrreversibleOrderError if nulls first/last is not a ↵Finn Young2019-02-172-1/+10
| | | | | | | | single ordering argument.
* | Fix `order` with custom attributesRyuta Kamizono2019-02-174-4/+21
| | | | | | | | This follows up 0ee96d13de29680e148ccb8e5b68025f29fd091c.
* | Merge pull request #35299 from kamipo/fix_mismatched_foreign_keyRyuta Kamizono2019-02-173-23/+115
|\ \ | | | | | | | | | Fix the regex that extract mismatched foreign key information
| * | Fix the regex that extract mismatched foreign key informationRyuta Kamizono2019-02-173-23/+115
|/ / | | | | | | | | | | | | | | | | | | | | | | | | The CI failure for `test_errors_for_bigint_fks_on_integer_pk_table` is due to the poor regex that extract all ``` `(\w+)` ``` like parts from the message (`:foreign_key` should be `"old_car_id"`, but `"engines"`): https://travis-ci.org/rails/rails/jobs/494123455#L1703 I've improved the regex more strictly and have more exercised mismatched foreign key tests. Fixes #35294
* | Merge pull request #35297 from yhara/fix-ar-connection-handler-leakRyuta Kamizono2019-02-161-7/+11
|\ \ | | | | | | | | | Fix possible memory leak of ConnectionHandler
| * | Fix possible memory leak of ConnectionHandlerYutaka HARA2019-02-161-7/+11
| | | | | | | | | | | | refs #35296
* | | Remove `NoForeignKeySupportTest` which is no longer reachedRyuta Kamizono2019-02-162-46/+0
| | | | | | | | | | | | Since #35212, foreign key feature is supported by all adapters.
* | | Refactor `remove_foreign_key` to delete the foreign key before `alter_table`Ryuta Kamizono2019-02-161-4/+2
|/ /
* | Add changelog entry for #35212Ryuta Kamizono2019-02-161-0/+4
| | | | | | | | [ci skip]
* | Merge pull request #35286 from matthewdunbar/masterRyuta Kamizono2019-02-162-0/+18
|\ \ | | | | | | | | | Properly handle cached queries with too many bind parameters
| * | Properly handle cached queries with too many bind parametersMatthew Dunbar2019-02-142-0/+16
| | |
* | | Deprecate using class level querying methods if the receiver scope regarded ↵Ryuta Kamizono2019-02-156-21/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | as leaked This deprecates using class level querying methods if the receiver scope regarded as leaked, since #32380 and #35186 may cause that silently leaking information when people upgrade the app. We need deprecation first before making those.
* | | Revert "Merge pull request #35186 from ↵Ryuta Kamizono2019-02-156-37/+38
|/ / | | | | | | | | | | | | | | | | | | | | | | kamipo/fix_leaking_scope_on_relation_create" This reverts commit b67d5c6dedbf033515a96a95d24d085bf99a0d07, reversing changes made to 2e018361c7c51e36d1d98bf770b7456d78dee68b. Reason: #35186 may cause that silently leaking information when people upgrade the app. We need deprecation first before making this.
* | Minor changes to deprecation warning message after 35242Abhay Nikam2019-02-153-6/+6
| |
* | Merge pull request #35242 from ↵Eileen M. Uchitelle2019-02-143-49/+141
|\ \ | |/ |/| | | | | eileencodes/add-setter-and-deprecation-for-configurations-hashes Add setter and deprecation for configurations hashes
| * Improve errors and handling of hashes for database configurationseileencodes2019-02-143-49/+141
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In chat Sam Saffron asked how to use the setter now that configurations is no longer a hash and you need to do AR::Base.configurations["test"]=. Technically you can do `ActiveRecord::Base.configurations = { the hash }` but I realized the old way throws an error and is unintuitive. To aid in the transition from hashes to objects this PR makes a few changes: 1) Re-adds a deprecated hash setter `[]=` that will add a new hash to the configurations list OR replace an existing hash if that environment is already present. This won't be supported in future Rails versions but a good error is important. 2) Changed to throw deprecation warnings on the methods we decided to support for hash conversion and raise on the methods we don't support. 3) Refactored the setter/getter hash deprecation warnings messages and rewrote them. Getters message: ``` DEPRECATION WARNING: `ActiveRecord::Base.configurations` no longer returns a hash. Methods that act on the hash like `values` are deprecated and will be removed in Rails 6.1. Use the `configs_for` method to collect and iterate over the database configurations. ``` Setter message: ``` DEPRECATION WARNING: Setting `ActiveRecord::Base.configurations` with `[]=` is deprecated. Use `ActiveRecord::Base.configurations=` directly to set the configurations instead. ``` 4) Rewrote the legacy configurations test file to test all the public methods in the DatabaseConfigurations class.
* | Revert "Chaining named scope is no longer leaking to class level querying ↵Ryuta Kamizono2019-02-146-15/+7
| | | | | | | | | | | | | | | | | | methods" This reverts #32380, since this may cause that silently leaking information when people upgrade the app. We need deprecation first before making this.
* | Merge pull request #35244 from palkan/fix/activerecord-database-uri-resolveEileen M. Uchitelle2019-02-132-1/+11
|\ \ | | | | | | Fix database configurations building when DATABASE_URL present
| * | Fix database configurations building when DATABASE_URL presentVladimir Dementyev2019-02-122-1/+11
| | |
* | | Revert "Merge pull request #35127 from bogdan/counter-cache-loading"Ryuta Kamizono2019-02-133-47/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit eec3e28a1abf75676dcee58308ee5721bb53c325, reversing changes made to 5588fb4802328a2183f4a55c36d6703ee435f85c. Reason: Marking as loaded without actual loading is too greedy optimization. See more context #35239. Closes #35239. [Edouard CHIN & Ryuta Kamizono]
* | | Support running AR isolated tests in parallelMatthew Draper2019-02-131-4/+35
|/ /
* | Should respect attribute_types over column_typesRyuta Kamizono2019-02-131-2/+1
| | | | | | | | Fixed the CI failure https://travis-ci.org/rails/rails/jobs/492291248#L1185-L1191.
* | Merge pull request #35237 from eileencodes/fix-teardown-in-db-selector-testEileen M. Uchitelle2019-02-121-0/+4
|\ \ | | | | | | Fix DatabaseSelector test that fails sometimes
| * | Fix DatabaseSelector test that fails sometimeseileencodes2019-02-121-0/+4
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On CI we've seen a few test failures when the DatabaseSelectorTest runs before the ConnectionHandlersMultiDbTest. This is because it's creating 2 handlers but not properly tearing them down. Example failure: ``` Failure: ActiveRecord::ConnectionAdapters::ConnectionHandlersMultiDbTest#test_connects_to_with_single_configuration [/rails/activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb:241]: Expected: 1 Actual: 2 ```
* | Fix `pluck` and `select` with custom attributesRyuta Kamizono2019-02-1310-16/+50
| | | | | | | | | | | | | | | | | | Currently custom attributes are always qualified by the table name in the generated SQL wrongly even if the table doesn't have the named column, it would cause an invalid SQL error. Custom attributes should only be qualified if the table has the same named column.
* | Avoid implicit delegation in the migration compatibilityRyuta Kamizono2019-02-121-12/+14
|/ | | | | | | The implicit delegation in the migration class is to be logged. It is not intended in the migration compatibility, so it should be avoided. Fixes #35224.
* Merge pull request #35196 from gmcgibbon/clarify_collection_proxy_docsGannon McGibbon2019-02-112-11/+25
|\ | | | | Clarify collection proxy docs
| * Clarify collection proxy docsGannon McGibbon2019-02-082-11/+25
| | | | | | | | | | | | | | | | | | The docs for `ActiveRecord::Associations::CollectionProxy` describe `ActiveRecord::Associations::Association`. I've moved them to association and rewrote collection proxy's docs to be more applicable to what the class actually does.` [ci skip]
* | Add `remove_foreign_key` for `change_table`Ryuta Kamizono2019-02-112-0/+22
| |
* | Fix typo a -> an, an -> a [ci skip]Ryuta Kamizono2019-02-112-2/+2
| |
* | SQLite3: Implement `add_foreign_key` and `remove_foreign_key`Ryuta Kamizono2019-02-119-21/+81
| | | | | | | | | | | | | | | | | | | | | | | | I implemented Foreign key create in `create_table` for SQLite3 at #24743. This follows #24743 to implement `add_foreign_key` and `remove_foreign_key`. Unfortunately SQLite3 has one limitation that `PRAGMA foreign_key_list(table-name)` doesn't have constraint name. So we couldn't implement find/remove foreign key by name for now. Fixes #35207. Closes #31343.
* | More exercise table name prefix and suffix testsRyuta Kamizono2019-02-115-33/+97
| |
* | Fix random CI failure due to non-deterministic sorting orderRyuta Kamizono2019-02-101-3/+3
| | | | | | | | https://travis-ci.org/rails/rails/jobs/491045821#L1528-L1531
* | Merge pull request #35203 from chiastolite/add_column_without_column_namesRyuta Kamizono2019-02-102-0/+12
|\ \ | | | | | | | | | Do not allow to add column without column name
| * | Do not allow to add column without column nameHiroyuki Morita2019-02-102-0/+10
|/ /
* | Refactor to extract defining column methods as `define_column_methods`Ryuta Kamizono2019-02-093-142/+161
| | | | | | | | | | It makes to ease to handle all short-hand methods (e.g. validates arguments etc).
* | Refactor to just use `Association#target=` in `associate_records_to_owner`Ryuta Kamizono2019-02-091-3/+2
| | | | | | | | | | | | | | | | | | | | | | `Association#target=` invokes `loaded!`, so we no longer need to call the `loaded!` explicitly. Since Preloader is private API, we don't guarantee that it behaves like older version as long as using Preloader directly. But this refactoring fortunately also fix the Preloader compatibility issue #35195. Closes #35195.
* | Merge pull request #34618 from bogdanvlviv/fix-elapsed-time-calculationsKasper Timm Hansen2019-02-082-6/+6
|\ \ | | | | | | Fix elapsed time calculations
| * | Fix elapsed time calculationsbogdanvlviv2019-02-082-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I've found a few places in Rails code base where I think it makes sense to calculate elapsed time more precisely by using `Concurrent.monotonic_time`: - Fix calculation of elapsed time in `ActiveSupport::Cache::MemoryStore#prune` - Fix calculation of elapsed time in `ActiveRecord::ConnectionAdapters::ConnectionPool::Queue#wait_poll` - Fix calculation of elapsed time in `ActiveRecord::ConnectionAdapters::ConnectionPool#attempt_to_checkout_all_existing_connections` - Fix calculation of elapsed time in `ActiveRecord::ConnectionAdapters::Mysql2Adapter#explain` See https://docs.ruby-lang.org/en/2.5.0/Process.html#method-c-clock_gettime https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way Related to 7c4542146f0dde962205e5a90839349631ae60fb
* | | Merge pull request #35193 from kamipo/fix_exists_with_distinct_and_offsetRyuta Kamizono2019-02-082-4/+18
|\ \ \ | | | | | | | | Fix `relation.exists?` with giving both `distinct` and `offset`
| * | | Fix `relation.exists?` with giving both `distinct` and `offset`Ryuta Kamizono2019-02-082-4/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `distinct` affects (reduces) rows of the result, so it is important part when both `distinct` and `offset` are given. Replacing SELECT clause to `1 AS one` and removing `distinct` and `order` is just optimization for the `exists?`, we should not apply the optimization for that case. Fixes #35191.
* | | | Merge pull request #35178 from bogdan/has-many-sizeRyuta Kamizono2019-02-082-2/+17
|\ \ \ \ | |/ / / |/| | | Bugfix has_many association #size when ids reader is cached and assoc…
| * | | Bugfix has_many association #size when ids reader is cached and association ↵Bogdan Gusiev2019-02-082-2/+17
| | | | | | | | | | | | | | | | is changed
* | | | Refactor extracting `current_scope_restoring_block` into the scoping classRyuta Kamizono2019-02-082-5/+9
| | | | | | | | | | | | | | | | Relation is not best place to do this.
* | | | Address `test_belongs_to_does_not_use_order_by` failure due to checking ↵Yasuo Honda2019-02-082-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | order by for metadata queries Also, `test_has_one_does_not_use_order_by` should not check metadata queries. Fixes #35098
* | | | Update CHANGELOG for database_resolver_contextJohn Hawthorn2019-02-071-2/+2
| | | |
* | | | Rename database_operations config to *_contextJohn Hawthorn2019-02-071-1/+1
| |_|/ |/| |