aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
* Delegate `ast` and `locked` to `arel` explicitlyRyuta Kamizono2017-05-061-0/+2
| | | | | | | | Currently `ast` and `locked` are used in the internal but delegating to `arel` is depend on `method_missing`. If a model class is defined these methods, `select_all` will be broken. It should be delegated to `arel` explicitly.
* Don't pass `arel.engine` to `Arel::SelectManager.new`Ryuta Kamizono2017-05-051-2/+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
* Merge pull request #28828 from kamipo/fix_extending_modules_on_associationRafael França2017-04-251-0/+2
|\ | | | | Mixin `CollectionProxy::DelegateExtending` after `ClassSpecificRelation`
| * Mixin `CollectionProxy::DelegateExtending` after `ClassSpecificRelation`Ryuta Kamizono2017-04-221-0/+2
| | | | | | | | | | | | | | | | | | | | `ClassSpecificRelation` has `method_missing` and the `method_missing` is called first. if an associated class has the missing method in a relation, never reach to the `method_missing` in the `CollectionProxy`. I extracted `DelegateExtending` and included it to the delegate class that including `ClassSpecificRelation` to fix the issue. Fixes https://github.com/rails/rails/pull/28246#issuecomment-296033784.
* | `respond_to_missing?` should be privateRyuta Kamizono2017-04-221-5/+3
|/ | | | | | | Follow up of 03d3f036. Some of `respond_to?` were replaced to `respond_to_missing?` in 03d3f036. But the visibility is still public. It should be private.
* Merge pull request #28767 from kamipo/rename_to_association_query_valueAndrew White2017-04-153-8/+9
|\ | | | | Rename `association_query_handler.rb` to `association_query_value.rb`
| * Rename `association_query_handler.rb` to `association_query_value.rb`Ryuta Kamizono2017-04-153-8/+9
| | | | | | | | | | | | Since `AssociationQueryHandler` and `PolymorphicArrayHandler` has removed in #28715, only exists `AssociationQueryValue` and `PolymorphicArrayValue` in these files.
* | Early return in `PredicateBuilder::ArrayHandler`Ryuta Kamizono2017-04-151-4/+3
|/ | | | Partitioning to `values` and `nils` is unneeded before early return.
* Merge pull request #28715 from ↵Andrew White2017-04-144-60/+32
|\ | | | | | | | | kamipo/convert_association_queries_to_poro_queries Convert association queries to PORO queries
| * `AssociationQueryValue#queries` returns an array for more concise ↵Ryuta Kamizono2017-04-112-14/+7
| | | | | | | | association handling
| * Convert `PolymorphicArrayValue` to PORO queriesRyuta Kamizono2017-04-093-28/+19
| |
| * Convert `AssociationQueryValue` to PORO queriesRyuta Kamizono2017-04-092-35/+23
| |
* | exclude ORDER BY clause for exists? (#28699)Boris Slobodin2017-04-101-1/+1
| |
* | Merge pull request #28713 from kamipo/expose_queries_for_association_queriesMatthew Draper2017-04-102-48/+44
|\| | | | | Expose `queries` for `AssociationQueryValue` and `PolymorphicArrayValue`
| * Expose `queries` for `AssociationQueryValue` and `PolymorphicArrayValue`Ryuta Kamizono2017-04-092-21/+25
| |
| * Avoid to handle polymorphic association for `AssociationQueryHandler`Ryuta Kamizono2017-03-282-29/+21
| | | | | | | | It should be handled by `PolymorphicArrayHandler` if polymorphic association.
* | Extract `construct_relation_for_exists` in `FinderMethods`Ryuta Kamizono2017-04-091-12/+15
| | | | | | | | To ease to customize a relation for `exists?`.
* | Revert "Merge pull request #28598 from wnadeau/patch-1"Rafael Mendonça França2017-04-031-1/+1
| | | | | | | | | | | | | | | | This reverts commit a680a5814184e2f37c4686aa53d0ad3c7fb6b1ee, reversing changes made to 842f67dd242e738419f27e752ea7dcd0bbe87b6d. Reason: I can't resist to the joke, so better to keep it there https://github.com/rails/rails/pull/28598#issuecomment-290945339.
* | FinderMethods#fourty_two docs cite proper sourceWinfred Nadeau2017-03-291-1/+1
|/ | | | | | | silly method gets a silly doc fix, or I'm missing an even sillier joke and I'm about to get schooled. BUT I'm pretty sure this is some serious Beaudrillard simulacrum, though. I'm just doing my part to spread the gospel of Douglas Adams.
* Merge pull request #28488 from kamipo/preprocess_association_query_handlingRafael França2017-03-271-13/+8
|\ | | | | Preprocess association query handling in predicate builder
| * Always need to extract `value.bound_attributes` if `value.is_a?(Relation)`Ryuta Kamizono2017-03-251-3/+1
| | | | | | | | Because `RelationHandler` uses `value.arel`.
| * Preprocess association query handling in predicate builderRyuta Kamizono2017-03-201-11/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently association query is handled as a postprocess. This has two problems. 1. When `value` is a `Hash`, we need to skip the postprocess using `next`. 2. `can_be_bound?` should return false if `table.associated_with?(column_name)` is true (pass to the postprocess). These are unneeded if preprocessing association query handling.
* | Fix where_clause#except with specific where valueJohn Hawthorn2017-03-201-2/+2
| | | | | | | | | | | | | | | | | | Fixes a regression introduced in 22ca710f20c3c656811df006cbf1f4dbc359f7a6 where Relation#unscope with a specific where value (vs unscoping the entire where clause) could result in the wrong binds being left on the query. This was caused by an index variable not being incremented properly.
* | 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
| | |