aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
Commit message (Collapse)AuthorAgeFilesLines
* fixes different `count` calculation when using `size` manual `select` with ↵jvillarejo2019-02-261-3/+8
| | | | | | | | DISTINCT When using `select` with `'DISTINCT( ... )'` if you use method `size` on a non loaded relation it overrides the column selected by passing `:all` so it returns different value than count. This fixes #35214
* Preparing for 6.0.0.beta2 releaseRafael Mendonça França2019-02-251-1/+1
|
* Merge pull request #35402 from alimi/update-ar-read-regexAaron Patterson2019-02-251-1/+1
|\ | | | | Support read queries with leading characters while preventing writes
| * Update READ_QUERY regexAli Ibrahim2019-02-251-1/+1
| | | | | | | | | | | | | | * The READ_QUERY regex would consider reads to be writes if they started with spaces or parens. For example, a UNION query might have parens around each SELECT - (SELECT ...) UNION (SELECT ...). * It will now correctly treat these queries as reads.
* | Refactor `type_to_sql` to handle converting `limit` to `size` in itselfRyuta Kamizono2019-02-264-67/+60
| | | | | | | | | | Also, improving an argument error message for `limit`, extracting around `type_to_sql` code into schema statements, and more exercise tests.
* | Fix prepared statements caching to be enabled even when query caching is enabledRyuta Kamizono2019-02-263-13/+20
|/ | | | | | | | | | | | Related cbcdecd, 2a56b2d. This is a regression caused by cbcdecd. If query caching is enabled, prepared statement handles are never re-used, since we missed that a query is preprocessed when query caching is enabled, but doesn't keep the `preparable` flag. We should care about that case.
* Merge pull request #35352 from kamipo/update_all_doesnt_care_optimistic_lockingRyuta Kamizono2019-02-251-10/+15
|\ | | | | Ensure `update_all` series doesn't care optimistic locking
| * Ensure `update_all` series cares about optimistic lockingRyuta Kamizono2019-02-251-10/+15
| | | | | | | | | | | | Incrementing the lock version invalidates any other process's optimistic lock, which is the desired outcome: the record no longer looks the same as it did when they loaded it.
* | minor grammar fix [ci skip]Shivam Jain2019-02-241-1/+1
| |
* | Fix `pluck` and `select` with `from` if `from` has original table nameRyuta Kamizono2019-02-221-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is caused by 0ee96d1. Since #18744, `select` columns doesn't be qualified by table name if using `from`. 0ee96d1 follows that for `pluck` as well. But people depends that `pluck` columns are qualified even if using `from`. So I've fixed that to be qualified if `from` has the original table name to keep the behavior as much as before. Fixes #35359.
* | Should not pass extra args to `_update_record`Ryuta Kamizono2019-02-213-7/+13
|/ | | | | | | | | | | | | | | | | | | | The argument of `_update_record` and `_create_record` is `attribute_names`, that is reserved for overriding by partial writes attribute names. https://github.com/rails/rails/blob/67e20d1d4854d834e9e43e56486d37cd98983f0d/activerecord/lib/active_record/persistence.rb#L719 https://github.com/rails/rails/blob/67e20d1d4854d834e9e43e56486d37cd98983f0d/activerecord/lib/active_record/persistence.rb#L737 https://github.com/rails/rails/blob/67e20d1d4854d834e9e43e56486d37cd98983f0d/activerecord/lib/active_record/attribute_methods/dirty.rb#L171 https://github.com/rails/rails/blob/67e20d1d4854d834e9e43e56486d37cd98983f0d/activerecord/lib/active_record/attribute_methods/dirty.rb#L177 The reason that no failing with extra args is that `Timestamp` module which is most outside module of the `_update_record` discards the extra args. https://github.com/rails/rails/blob/67e20d1d4854d834e9e43e56486d37cd98983f0d/activerecord/lib/active_record/timestamp.rb#L104 But that looks odd dependency. It should not be passed extra args, should only be passed attribute names.
* Address "warning: in `column': the last argument was passed as a single Hash"Ryuta Kamizono2019-02-212-4/+4
|
* Extract `default_uniqueness_comparison` to ease to handle mismatched ↵Ryuta Kamizono2019-02-212-1/+7
| | | | | | | | | | | | | | | | | | collation issues In MySQL, the default collation is case insensitive. Since the uniqueness validator enforces case sensitive comparison by default, it frequently causes mismatched collation issues (performance, weird behavior, etc) to MySQL users. https://grosser.it/2009/12/11/validates_uniqness_of-mysql-slow/ https://github.com/rails/rails/issues/1399 https://github.com/rails/rails/pull/13465 https://github.com/gitlabhq/gitlabhq/commit/c1dddf8c7d947691729f6d64a8ea768b5c915855 https://github.com/huginn/huginn/pull/1330#discussion_r55152573 This extracts `default_uniqueness_comparison` to ease to handle the mismatched collation issues on the connection.
* Fix lint `ShadowingOuterLocalVariable`soartec-lab2019-02-211-3/+3
| | | | | | | | | | Revert "Fix lint `ShadowingOuterLocalVariable`" This reverts commit 38bd45a48992b500478a82d56d31468a322937a8. Change of variable name Fix lint `ShadowingOuterLocalVariable`
* Merge pull request #35263 from hatch-carl/reduce-postgres-uuid-allocationsRyuta Kamizono2019-02-211-3/+6
|\ | | | | Reduce unused allocations when casting UUIDs for Postgres
| * Reduce unused allocations when casting UUIDs for PostgresCarl Thuringer2019-02-201-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using the subscript method `#[]` on a string has several overloads and rather complex implementation. One of the overloads is the capability to accept a regular expression and then run a match, then return the receiver (if it matched) or one of the groups from the MatchData. The function of the `UUID#cast` method is to cast a UUID to a type and format acceptable by postgres. Naturally UUIDs are supposed to be string and of a certain format, but it had been determined that it was not ideal for the framework to send just any old string to Postgres and allow the engine to complain when "foobar" or "" was sent, being obviously of the wrong format for a valid UUID. Therefore this code was written to facilitate the checking, and if it were not of the correct format, a `nil` would be returned as is conventional in Rails. Now, the subscript method will allocate one or more strings on a match and return one of them, based on the index parameter. However, there is no need for a new string, as a UUID of the correct format is already such, and so long as the format was verified then the string supplied is adequate for consumption by the database. The subscript method also creates a MatchData object which will never be used, and so must eventually be garbage collected. Garbage collection indeed. This innocuous method tends to be called quite a lot, for example if the primary key of a table is a uuid, then this method will be called. If the foreign key of a relation is a UUID, once again this method is called. If that foreign key is belonging to a has_many relationship with dozens of objects, then again dozens of UUIDs shall be cast to a dup of themselves, and spawn dozens of MatchData objects, and so on. So, for users that: * Use UUIDs as primary keys * Use Postgres * Operate on collections of objects This accomplishes a significant savings in total allocations, and may save many garbage collections.
* | Merge pull request #35327 from abhaynikam/use-delete-by-and-destroy-by-methodRyuta Kamizono2019-02-203-3/+3
|\ \ | | | | | | Replaced usage of where.delete/destroy_all with delete/destroy_by
| * | Replaced usage of where.delete/destroy_all with delete/destroy_byAbhay Nikam2019-02-203-3/+3
| |/
* | Merge pull request #35247 from bogdan/fix-source-reflection-reset-codeRyuta Kamizono2019-02-202-21/+10
|\ \ | | | | | | Fix reset of the source association when through association is loaded
| * | Fix reset of the source association when through association is loadedBogdan Gusiev2019-02-202-21/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | The special case happens when through association has a custom scope that is applied to the source association when loading. In this case, the soucre association would need to be reset after main association is loaded. See tests. The special case exists when a through association has
* | | PostgreSQL: Support endless range values for range typesRyuta Kamizono2019-02-202-2/+2
| |/ |/|
* | Merge pull request #35316 from abhaynikam/35304-add-delete_by_and_destroy_byRyuta Kamizono2019-02-192-1/+27
|\ \ | | | | | | | | | Introduce delete_by and destroy_by methods to ActiveRecord::Relation
| * | Introduce delete_by and destroy_by methods to ActiveRecord::RelationAbhay Nikam2019-02-192-1/+27
|/ /
* | Don't allow `where` with invalid value matches to nil valuesRyuta Kamizono2019-02-181-2/+4
| | | | | | | | | | | | | | | | | | That is considered as silently leaking information. If type casting doesn't return any actual value, it should not be matched to any record. Fixes #33624. Closes #33946.
* | 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-184-25/+29
| | | | | | | | | | | | 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-171-1/+1
|\ \ | | | | | | 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-171-1/+1
| | | | | | | | | | | | single ordering argument.
* | | Fix `order` with custom attributesRyuta Kamizono2019-02-171-2/+8
| | | | | | | | | | | | This follows up 0ee96d13de29680e148ccb8e5b68025f29fd091c.
* | | Fix the regex that extract mismatched foreign key informationRyuta Kamizono2019-02-172-20/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | | | Refactor `remove_foreign_key` to delete the foreign key before `alter_table`Ryuta Kamizono2019-02-161-4/+2
|/ / /
* | | Merge pull request #35286 from matthewdunbar/masterRyuta Kamizono2019-02-161-0/+6
|\ \ \ | | | | | | | | | | | | Properly handle cached queries with too many bind parameters
| * | | Properly handle cached queries with too many bind parametersMatthew Dunbar2019-02-141-0/+6
| | | |
* | | | Deprecate using class level querying methods if the receiver scope regarded ↵Ryuta Kamizono2019-02-153-7/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-152-19/+2
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-152-4/+4
| | |
* | | Merge pull request #35242 from ↵Eileen M. Uchitelle2019-02-141-6/+24
|\ \ \ | |/ / |/| | | | | | | | 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-141-6/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-142-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-131-1/+1
|\ \ \ | | | | | | | | Fix database configurations building when DATABASE_URL present
| * | | Fix database configurations building when DATABASE_URL presentVladimir Dementyev2019-02-121-1/+1
| | | |
* | | | Revert "Merge pull request #35127 from bogdan/counter-cache-loading"Ryuta Kamizono2019-02-132-11/+6
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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]
* | | 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.
* | | Fix `pluck` and `select` with custom attributesRyuta Kamizono2019-02-132-9/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-111-0/+11
| | |