aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
* Use `load` rather than `collect` for force loadingRyuta Kamizono2017-03-191-1/+1
| | | | | | | Since b644964b `ActiveRecord::Relation` includes `Enumerable` so delegating `collect`, `all?`, and `include?` are also unneeded. `collect` without block returns `Enumerable` without preloading by that. We should use `load` rather than `collect` for force loading.
* Delegate `uniq` to `records`Ryuta Kamizono2017-03-181-1/+1
| | | | | | | | | | This fixes CI failure due to 48f3be8c. `Enumerable#uniq` was introduced since Ruby 2.4. We should delegate `uniq` to `records` explicitly. And since b644964b `ActiveRecord::Relation` includes `Enumerable` so delegating `map` is unneeded.
* Merge pull request #28191 from eugeneius/string_assoc_orderRafael França2017-03-171-1/+6
|\ | | | | Allow order to be given expressions as hash keys
| * Allow order to be given expressions as hash keysEugene Kenny2017-02-271-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | When `order` is given a hash, the keys are currently assumed to be attribute names and are quoted as such in the query, which makes it impossible to pass an expression instead: Post.order("LENGTH(title)" => :asc).last # SELECT `posts`.* FROM `posts` ORDER BY `posts`.`LENGTH(title)` DESC LIMIT 1 If the key is an `Arel::Nodes::SqlLiteral`, we now use it directly in the query. This provides a way to build a relation with a complex order clause that can still be reversed with `reverse_order` or `last`.
* | Merge pull request #28371 from kamipo/simplify_countAndrew White2017-03-121-7/+4
|\ \ | | | | | | Simply forward `Calculations#count` to `Enumerable#count`
| * | Simply forward `Calculations#count` to `Enumerable#count`Ryuta Kamizono2017-03-101-7/+4
| | | | | | | | | | | | | | | | | | | | | Follow up of #24203. Since b644964b `ActiveRecord::Relation` includes `Enumerable` so it is enough to call `super` simply.
* | | Simply delegate `as_json` to `records`Ryuta Kamizono2017-03-101-1/+1
|/ /
* | Merge pull request #25274 from kamipo/fix_find_nth_with_limit_valueAndrew White2017-02-261-3/+7
|\ \ | |/ |/| Fix `find_nth` with `limit_value`
| * Fix `find_nth` with `limit_value`Ryuta Kamizono2017-02-261-3/+7
| | | | | | | | | | If the `index` exceeds a `limit`, simply return an empty result without querying the database.
* | Include selects in group query with having clauseEugene Kenny2017-02-261-0/+1
|/ | | | | | | | | | | | | | When a grouped calculation contains a having clause that references a selected value, we need to include that selected value in the query. Postgres doesn't support referencing a selected value in a having clause, but other databases do; we can skip the test on the pg adapter but run it for the others. This was fixed before in 9a298a162c16e019fe6971e563e7f4916e86ced6, but the test coverage was lost in 5a05207d99b7e2678f9b42db2d9ffc21ec2c8c3b. The fix regressed in 6311975fb3c02f50730fd1e11b8dba8dd9c05306 and was removed in 97d46c17ea9113b0ce970167f5208c8d9170915c.
* Merge pull request #28177 from kami-zh/remove-duplicated-privateAndrew White2017-02-261-102/+100
|\ | | | | Remove duplicated private method in ActiveRecord::FinderMethods
| * Remove duplicated private methodkami-zh2017-02-261-102/+100
| |
* | Remove useless `select_values += select_values`Ryuta Kamizono2017-02-261-1/+0
|/ | | | | `select_values` is a local variable defined at previous line. `select_values += select_values` is totally useless.
* Suppress `DISTINCT` clause outside aggregate functionRyuta Kamizono2017-02-251-2/+2
| | | | | | | | | | | | | | | | | | `DISTINCT` clause is applied inside aggregate function by `operation_over_aggregate_column` if needed. Unneeded outside aggregate function. ```ruby # Before author.unique_categorized_posts.count # => SELECT DISTINCT COUNT(DISTINCT "posts"."id") FROM "posts" INNER JOIN "categorizations" ON "posts"."id" = "categorizations"."post_id" WHERE "categorizations"."author_id" = ? [["author_id", 2]] # After author.unique_categorized_posts.count # => SELECT COUNT(DISTINCT "posts"."id") FROM "posts" INNER JOIN "categorizations" ON "posts"."id" = "categorizations"."post_id" WHERE "categorizations"."author_id" = ? [["author_id", 2]] ``` Closes #27615
* Merge pull request #27122 from kamipo/fix_unscope_with_subqueryRafael França2017-02-131-14/+26
|\ | | | | Fix unscope with subquery
| * Refactor `except_predicates_and_binds` to avoid `tap`Ryuta Kamizono2017-02-131-12/+15
| |
| * Fix unscope with subqueryRyuta Kamizono2016-12-051-10/+19
| | | | | | | | | | | | | | Currently cannot unscope subquery properly. This commit fixes the issue. Fixes #26323.
* | Merge pull request #27904 from ↵Eileen M. Uchitelle2017-02-101-0/+1
|\ \ | | | | | | | | | | | | kenta-s/add-methods-back-to-array-delegation-from-ar-relation Delegate `to_sentence` and `to_fomatted_s` to `records`
| * | Delegate `to_sentence` and `to_fomatted_s` to `records`kenta-s2017-02-041-0/+1
| | |
* | | Revert "Remove useless `column_alias` in `subquery_for_count`"Ryuta Kamizono2017-02-071-2/+3
| | | | | | | | | | | | This reverts commit 28977f1fa3d7b15c1608174a165e60b71ddf3995.
* | | Merge pull request #26378 from ↵Jeremy Daer2017-02-061-3/+43
|\ \ \ | | | | | | | | | | | | | | | | kamipo/decouple_building_arel_ast_for_uniqueness_validator Decouple the building Arel ASTs for uniqueness validator
| * | | Decouple the building Arel ASTs for uniqueness validatorRyuta Kamizono2016-12-251-3/+43
| | | | | | | | | | | | | | | | | | | | | | | | Currently uniqueness validator is coupled with building Arel ASTs. This commit extracts `WhereClauseFactory#build_for_case_sensitive` for decouple the building Arel ASTs.
* | | | Remove useless `column_alias` in `subquery_for_count`Ryuta Kamizono2017-02-061-3/+2
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | If select clause is specified and last column has a column alias, additional column alias causes a statement invalid. Add test coverage for counting a single column with NULL values. Fixes #27676, #27682, and #27705.
* | | Fix grammar typo about sort in finder_methods.rbKevin Huang2017-01-301-2/+2
| | |
* | | Privatize unneededly protected methods in Active RecordAkira Matsuda2017-01-051-1/+1
| | |
* | | `self.` is not needed when calling its own instance methodAkira Matsuda2017-01-053-3/+3
| | | | | | | | | | | | Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
* | | Remove unneeded requires at active recordRafael Mendonça França2017-01-031-1/+0
| | |
* | | Raise ArgumentError when a instance of ActiveRecord::Base is passed toRafael Mendonça França2017-01-031-7/+5
| | | | | | | | | | | | find and exists?
* | | Mark internal cache constants as privateMatthew Draper2016-12-311-1/+4
| | | | | | | | | | | | Closes #14640
* | | Remove deprecated `#uniq`, `#uniq!`, and `#uniq_value`Ryuta Kamizono2016-12-301-4/+0
| | |
* | | Remove deprecated support to passing arguments to `#select` when a block is ↵Rafael Mendonça França2016-12-291-3/+1
| | | | | | | | | | | | provided.
* | | Remove deprecated support to query using commas on LIMITRafael Mendonça França2016-12-291-19/+2
| | |
* | | Remove deprecated support to passing a class as a value in a queryRafael Mendonça França2016-12-292-31/+0
| | |
* | | Raises IrreversibleOrderError when using last with an irreversible orderRafael Mendonça França2016-12-291-8/+0
| | |
* | | Merge pull request #26376 from kamipo/remove_polymorphic_base_class_for_arrayRafael França2016-12-291-3/+0
|\ \ \ | | | | | | | | Remove extracting `polymorphic_base_class` for `Array` in `AssociationQueryValue`
| * | | Remove extracting `polymorphic_base_class` for `Array` in ↵Ryuta Kamizono2016-09-211-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | `AssociationQueryValue` It is handled by `PolymorphicArrayValue`.
* | | | Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-98/+98
| |/ / |/| | | | | | | | | | | | | | Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API.
* | | Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-242-13/+11
| | |
* | | No need to nodoc private methodsAkira Matsuda2016-12-241-1/+1
| | |
* | | Describe what we are protectingAkira Matsuda2016-12-238-0/+16
| | |
* | | Translate numeric value out of range to the specific exceptionRyuta Kamizono2016-12-061-4/+4
| |/ |/| | | | | Raise `ActiveRecord::RangeError` when values that executed are out of range.
* | Restore RecordNotFound when *_ids= can't find records by IDDominic Cleal2016-11-241-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 9c9fb19 changed the behaviour of the _ids= setters for associations to raise an AssociationTypeMismatch when unknown IDs are given: Class: <ActiveRecord::AssociationTypeMismatch> Message: <"Developer(#43811860) expected, got NilClass(#16732720)"> This restores the original ActiveRecord::RecordNotFound exception with a much clearer error message: Class: <ActiveRecord::RecordNotFound> Message: <"Couldn't find all Developers with 'id': (1, -9999) [WHERE \"contracts\".\"company_id\" = ?] (found 1 results, but was looking for 2)"> Fixes #25719
* | Merge pull request #26981 from kamipo/should_not_except_order_for_existsRafael França2016-11-171-1/+1
|\ \ | | | | | | Should except `:distinct` rather than `:order` for `exists?`
| * | Should except `:distinct` rather than `:order` for `exists?`Ryuta Kamizono2016-11-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Records fetching order is very important for performance if `limit` is presented. Should not except the order in the case. And `exists?` replaces select list to `1 AS one` therefore `:distinct` is useless (`DISTINCT 1 AS one`). And PostgreSQL raises the following error if `:distinct` and `:order` are used in the same time. ``` ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list ```
* | | Call `spawn` and bang method for `none`Ryuta Kamizono2016-11-141-1/+1
|/ / | | | | | | All query methods calls `spawn` and bang method, but only `none` is not.
* | Avoid `unscope(:order)` when `limit_value` is presented for `count`Ryuta Kamizono2016-11-061-6/+6
| | | | | | | | | | If `limit_value` is presented, records fetching order is very important for performance. Should not unscope the order in the case.
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
| |
* | removes requires already present in active_support/railsXavier Noria2016-10-271-2/+0
| |
* | let Regexp#match? be globally availableXavier Noria2016-10-272-2/+0
| | | | | | | | | | | | Regexp#match? should be considered to be part of the Ruby core library. We are emulating it for < 2.4, but not having to require the extension is part of the illusion of the emulation.
* | Fix regression caused due to removal of select method from CollectionAssociationPrathamesh Sonpatki2016-10-221-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - CollectionAssociation#select was removed in https://github.com/rails/rails/pull/25989 in favor of QueryMethods#select but it caused a regression when passing arguments to select and a block. - This used to work earlier in Rails 4.2 and Rails 5. See gist https://gist.github.com/prathamesh-sonpatki/a7df922273473a77dfbc742a4be4b618. - This commit restores the behavior of Rails 4.2 and Rails 5.0.0 to allow passing arguments and block at the same time but also deprecates it. - Because, these arguments do not have any effect on the output of select when select is used with a block. - Updated documentation to remove the example passing arguments and block at the same time to `CollectionProxy#select`.