aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/collection_cache_key.rb
Commit message (Collapse)AuthorAgeFilesLines
* Ensure `apply_join_dependency` for `collection_cache_key` if eager-loading ↵Ryuta Kamizono2017-11-061-0/+3
| | | | | | is needed Fixes #30315.
* Don't use `collection.table_name` in `collection_cache_key`Ryuta Kamizono2017-09-141-1/+1
| | | | | Because `collection.table_name` doesn't respect table alias. Use `collection.arel_attribute` instead.
* Merge pull request #29848 from kamipo/fix_distinct_count_with_order_and_limitRafael França2017-07-241-1/+1
|\ | | | | Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT`
| * Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT`Ryuta Kamizono2017-07-221-1/+1
| | | | | | | | | | | | | | Since #26972, `ORDER BY` is kept if `LIMIT` is presented for performance. But in most SQL servers (e.g. PostgreSQL, SQL Server, etc), `ORDER BY` expressions must appear in select list for `SELECT DISTINCT`. We should not replace existing select list in that case.
* | Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-1/+1
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common source of bugs and code bloat within Active Record has been the need for us to maintain the list of bind values separately from the AST they're associated with. This makes any sort of AST manipulation incredibly difficult, as any time we want to potentially insert or remove an AST node, we need to traverse the entire tree to find where the associated bind parameters are. With this change, the bind parameters now live on the AST directly. Active Record does not need to know or care about them until the final AST traversal for SQL construction. Rather than returning just the SQL, the Arel collector will now return both the SQL and the bind parameters. At this point the connection adapter will have all the values that it had before. A bit of this code is janky and something I'd like to refactor later. In particular, I don't like how we're handling associations in the predicate builder, the special casing of `StatementCache::Substitute` in `QueryAttribute`, or generally how we're handling bind value replacement in the statement cache when prepared statements are disabled. This also mostly reverts #26378, as it moved all the code into a location that I wanted to delete. /cc @metaskills @yahonda, this change will affect the adapters Fixes #29766. Fixes #29804. Fixes #26541. Close #28539. Close #24769. Close #26468. Close #26202. There are probably other issues/PRs that can be closed because of this commit, but that's all I could find on the first few pages.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Don't pass `arel.engine` to `Arel::SelectManager.new`Ryuta Kamizono2017-05-051-1/+1
| | | | | | The argument of `Arel::SelectManager.new` is `table`, not `engine`. https://github.com/rails/arel/blob/v8.0.0/lib/arel/select_manager.rb#L10
* `cache_key` respects the limit in a relation even if a relation is not loadedRyuta Kamizono2017-04-171-6/+16
| | | | | | `cache_key` includes the size of a relation. But if a relation is not loadded, the size is not respected even if a relation has a limit. It should be respected for consistency.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* Address ORA-00923 error by quoting a reserved word "SIZE"Yasuo Honda2016-04-161-1/+1
|
* Fix AR::Relation#cache_key to remove select scope added by userPrathamesh Sonpatki2016-01-241-0/+1
| | | | | | | | | | - We don't need the select scope added by user as we only want to max timestamp and size of the collection. So we already know which columns to select. - Additionally having user defined columns in select scope blows the cache_key method with PostGreSQL because it needs all `selected` columns in the group_by clause or aggregate function. - Fixes #23038.
* Fix ActiveRecord::Relation#cache_key for relations with no resultsPrathamesh Sonpatki2016-01-221-2/+8
| | | | | | | - When relations return no result or 0 result then cache_key should handle it gracefully instead of blowing up trying to access `result[:size]` and `result[:timestamp]`. - Fixes #23063.
* Fix ActiveRecord::Relation#cache_key for loaded empty collectionPrathamesh Sonpatki2016-01-161-1/+3
| | | | | | | | | - Before this patch if we try to find cache_key of a loaded but empty collection it used to give error because of trying to call `updated_at` on `nil` value generated by `collection.max_by(&timestamp_column).public_send(timestamp_column)`. - This commit fixes above error by checking if size is greater than zero or not.
* Fix test failures caused by #20884Sean Griffin2015-08-011-1/+3
| | | | | | | PostgreSQL is strict about the usage of `DISTINCT` and `ORDER BY`, which one of the tests demonstrated. The order clause is never going to be relevant in the query we're performing, so let's just remove it entirely.
* Add #cache_key to ActiveRecord::Relation.Alberto F. Capel2015-07-201-0/+29