aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
...
* Merge branch 'master' into fix_unscope_where_column_with_orSean Griffin2017-07-184-14/+14
|\
| * Fix `JoinDependency` with using a custom tableRyuta Kamizono2017-07-183-7/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without this fix, `JoinDependency` doesn't use a custom table alias: ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/relations_test.rb -n test_using_a_custom_table_with_joins_affects_the_wheres Using sqlite3 Run options: -n test_using_a_custom_table_with_joins_affects_the_wheres --seed 14531 E Error:RelationTest#test_using_a_custom_table_with_joins_affects_the_wheres: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: posts.author_id: SELECT "omg_posts".* FROM "posts" "omg_posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" WHERE "omg_posts"."title" = ? LIMIT ? ```
| * Fix `where` with a custom tableRyuta Kamizono2017-07-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without this fix, SELECT clause doesn't use a custom table alias name: ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/relations_test.rb -n test_using_a_custom_table_affects_the_wheres Using sqlite3 Run options: -n test_using_a_custom_table_affects_the_wheres --seed 31818 E Error: RelationTest#test_using_a_custom_table_affects_the_wheres: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: posts: SELECT "posts".* FROM "posts" "omg_posts" WHERE "omg_posts"."title" = ? LIMIT ? ```
| * Remove useless `arel_engine`Ryuta Kamizono2017-07-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | `arel_engine` is only used in `raise_record_not_found_exception!` to use `engine.connection` (and `connection.visitor`) in `arel.where_sql`. https://github.com/rails/arel/blob/v8.0.0/lib/arel/select_manager.rb#L183 But `klass.connection` will work as expected even if not using `arel_engine` (described by `test_connection`). So `arel_engine` is no longer needed.
| * Fix code formatting for QueryMethods#selectRobin Dupret2017-07-161-2/+3
| | | | | | | | [ci skip]
| * Fix `create_with` using both string and symbolRyuta Kamizono2017-07-162-3/+3
| | | | | | | | | | | | | | This is related with #27680. Since `where_values_hash` keys constructed by `where` are string, so we need `stringify_keys` to `create_with_value` before merging it.
* | Bugfix: unscope(where: [columns]) would not remove the correct binds sometimesMaxime Lapointe2017-07-131-1/+2
|/ | | | | Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).where_clause.binds.map(&:value) Would return [2, 3] instead of the expected [1,2]
* Skip query cache for in_batches and friendsEugene Kenny2017-07-064-6/+12
| | | | | | | | | | | The `find_each`, `find_in_batches` and `in_batches` APIs usually operate on large numbers of records, where it's preferable not to load them all into memory at once. If the query cache is enabled, it will hold onto the query results until the end of the execution context (request/job), which means the memory used is still proportional to the total number of records. These queries are typically not repeated, so the query cache isn't desirable here.
* Merge branch 'master' into require_relative_2017Xavier Noria2017-07-021-2/+2
|\
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-0221-21/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-0221-0/+21
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-0121-0/+21
| | |
| * | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-021-2/+2
| |\ \ | | |/ | |/| | | | Make ActiveSupport frozen-string-literal friendly.
| | * Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-2/+2
| | |
* | | [Active Record] require => require_relativeAkira Matsuda2017-07-015-15/+15
|/ /
* | Fix the next version of Rails from 5.3 to 6.0Ryuta Kamizono2017-06-291-2/+2
| |
* | Deprecate delegating to `arel` in `Relation`Ryuta Kamizono2017-06-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Active Record doesn't rely delegating to `arel` in the internal since 425f2ca. The delegation is a lower priority than delegating to `klass`, so it is pretty unclear which method is delegated to `arel`. For example, `bind_values` method was removed at b06f64c (a series of changes https://github.com/rails/rails/compare/79f71d3...b06f64c). But a relation still could respond to the method because `arel` also have the same named method (#28976). Removing the delegation will achieve predictable behavior.
* | Merge pull request #28932 from ↵Rafael França2017-06-281-10/+0
|\ \ | | | | | | | | | | | | kamipo/remove_method_missing_in_relation_delegation Remove `method_missing` in `Relation::Delegation`
| * | Remove `method_missing` in `Relation::Delegation`Ryuta Kamizono2017-04-301-10/+0
| | | | | | | | | | | | The `method_missing` is never reached since 64c53d7c.
* | | Merge pull request #29405 from kamipo/locked_should_not_build_arelRafael França2017-06-283-8/+4
|\ \ \ | | | | | | | | `Relation#locked?` should not build arel
| * | | Remove delegating to arel in a relationRyuta Kamizono2017-06-293-8/+4
| | |/ | |/| | | | | | | | | | The delegation was needed since passing `relation` with `relation.bound_attributes`. It should use `relation.arel` in that case.
* | | Merge pull request #29556 from kamipo/extract_ordered_relationRafael França2017-06-271-12/+11
|\ \ \ | | | | | | | | Extract `ordered_relation` in `FinderMethods`
| * | | Extract `ordered_relation` in `FinderMethods`Ryuta Kamizono2017-06-241-12/+11
| |/ /
* / / Fix extracting `references` via `order_values` to respect quotingRyuta Kamizono2017-06-261-1/+1
|/ /
* | Don't require 'unscope' to be the same for both sides of a 'or' relation.Dan Sherson2017-06-151-1/+1
| |
* | Prevent making bind param if casted value is nilRyuta Kamizono2017-05-312-8/+13
| | | | | | | | | | | | | | | | If casted value is nil, generated SQL should be `IS NULL`. But currently it is generated as `= NULL`. To prevent this behavior, avoid making bind param if casted value is nil. Fixes #28945.
* | Don't expose methods and attrs for internal usageRyuta Kamizono2017-05-302-4/+10
| |
* | Merge pull request #29098 from kamipo/fix_association_with_extension_issuesMatthew Draper2017-05-301-2/+0
|\ \ | | | | | | | | | Fix association with extension issues
| * | Fix association with extension issuesRyuta Kamizono2017-05-281-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* | | Deprecate passing arguments and block at the same time to `count` and `sum` ↵Ryuta Kamizono2017-05-291-2/+20
| | | | | | | | | | | | | | | | | | | | | | | | in `ActiveRecord::Calculations` `select`, `count`, and `sum` in `Relation` are also `Enumerable` method that can be passed block. `select` with block already doesn't take arguments since 4fc3366. This is follow up of that.
* | | Merge pull request #29003 from kamipo/delegate_ast_and_locked_to_arel_explicitlyMatthew Draper2017-05-281-0/+2
|\ \ \ | |/ / |/| | Delegate `ast` and `locked` to `arel` explicitly
| * | 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.
* | | Doc updates for ActiveRecord::BatchesT.J. Schuck2017-05-261-12/+12
| | | | | | | | | [ci skip]
* | | Avoid circular require due to autoloadMatthew Draper2017-05-261-9/+9
| | |
* | | Make `VALID_DIRECTIONS` to `Set`Ryuta Kamizono2017-05-201-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```ruby require "benchmark/ips" require "set" array = [:asc, :desc, :ASC, :DESC, "asc", "desc", "ASC", "DESC"] set = array.to_set item = "DESC" Benchmark.ips do |x| x.report "array" do array.include?(item) end x.report "set" do set.include?(item) end end ``` ``` % ruby array_vs_set.rb Warming up -------------------------------------- array 188.441k i/100ms set 229.531k i/100ms Calculating ------------------------------------- array 3.508M (± 9.0%) i/s - 17.525M in 5.043058s set 5.134M (± 7.6%) i/s - 25.707M in 5.038921s ```
* | | Merge pull request #28919 from ↵Kasper Timm Hansen2017-05-121-1/+1
|\ \ \ | | | | | | | | | | | | | | | | meinac/fix_ambigious_exception_message_of_select_query_method Fix ambigious error message of select query method [ci skip]
| * | | Fix ambigious error message of select query methodMehmet Emin INAC2017-05-081-1/+1
| | |/ | |/|
* | | Don't eager loading if unneeded for `FinderMethods#exists?`Ryuta Kamizono2017-05-111-2/+4
| |/ |/| | | | | Fixes #29025.
* | 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
| |