aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/calculations.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-2/+2
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* reuse available belongs_to? methodeileencodes2014-06-031-1/+1
| | | | | | | | | | Reflection has a `belongs_to?` method. Instead of checking for `macro == :belongs_to` throughout the source reuse existing method. I also bumped `foreign_key_present?` method onto on line because the `belongs_to?` makes it shorter than other longer lines in the same class.
* Remove unused `initialize_attributes` methodSean Griffin2014-06-021-1/+1
| | | | | This was previously a hook for a special case related to `serialize`, which has since been removed.
* Merge pull request #15210 from arthurnn/fix_hbtm_reflectionArthur Neves2014-05-241-1/+1
| | | | | | | | | Fix habtm reflection Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/counter_cache.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/reflection_test.rb
* docs, explain usage of `count` + `select`. Closes #15065. [ci skip]Yves Senn2014-05-131-0/+8
|
* push up bind params on "simple" subquery calculationsAaron Patterson2014-05-021-2/+4
| | | | | bind parameters we not being propogated to simple subquery calculation calls. This fixes it
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-201-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (74 commits) [ci skip] builtin -> built-in Fix code indentation and improve formatting Grammar fix in Getting Started Guide Make URL escaping more consistent Optimize URI escaping Always escape string passed to url helper. Remove statement assuming coffee shop/public space wifi is inherently insecure Don't rely on Arel master in bug report template [ci skip] wrap methods in backticks [ci skip] "subhash" --> "sub-hash" multibyte_conformance.rb --> multibyte_conformance_test.rb Fix inconsistent behavior from String#first/#last `@destroyed` should always be set to `false` when an object is duped. remove warning `warning: ambiguous first argument; put parentheses or even spaces` :uglify -> :uglifier Regression test for irregular inflection on has_many Singularize association names before camelization Fix spelling and proper nouns Optimize select_value, select_values, select_rows and dry up checking whether to exec with cache for Postgresql adapter Include default rails protect_from_forgery with: :exception ... Conflicts: activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
| * Make sure the column_name is different from 'all'.Lauro Caetano2014-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 968c581ea34b5236af14805e6a77913b1cb36238 have fixed the EagerLoadTest, but not in the correct way. The problem was when `empty?` or `size` was called on relation. It was triggering `count(:all)`, which was passing `:all` as the column name to `count` on Calculations. On the other hand, the method `calculate` on Calculations was calling `construct_relation_for_association_calculations` instead of `perform_calculation`, because `has_include?` was returning `true` since `column_name` was present. To prevent calling the wrong method to perform the calculation, we have to check if the `column_name` is present and if it is different from `:all` (which is now used to correctly do `count` with `select`). More information here: https://github.com/rails/rails/commit/968c581ea34b5236af14805e6a77913b1cb36238#commitcomment-6006135
* | Merge branch 'master' into adequaterecordAaron Patterson2014-04-071-1/+1
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (122 commits) Rails.application should be set inside before_configuration hook remove check for present? from delete_all Remove useless begin..end Build the reverse_order on its proper method. Use connection-specific bytea escaping Ignore order when doing count. make enums distinct per class Remove unused `subclass_controller_with_flash_type_bar` var from flash test. fix CollectionProxy delete_all documentation Added OS X specific commands to installation guide [ci skip] Recommended using homebrew for installing MySQL and PostgreSQL Fix setup of adding _flash_types test. Use SVG version of travis build status badge [skip ci] W3C CSP document moved to gihub.io URL [ci skip] sprockets-rails was released Fix the test defining the models in the right place Add CHANGELOG entry for #11650 [ci skip] Declare the assets dependency Use sass-rails 4.0.3 Make possible to use sprockets-rails 2.1 add missing parentheses to validates_with documentation [skip ci] ...
| * Ignore order when doing count.Lauro Caetano2014-04-071-1/+1
| | | | | | | | | | | | | | This is necessary because Postgresql doesn't play nice with ORDER BY and no GROUP BY. Fixes #14621.
* | adding bind values to the manager objectAaron Patterson2014-01-131-1/+5
|/
* Mark the arguments needed by activerecord-deprecated_finders with a TODORafael Mendonça França2013-12-111-0/+12
|
* Revert "Merge pull request #12518 from vipulnsward/remove_count_options"Rafael Mendonça França2013-12-111-12/+13
| | | | | | | It is needed for activerecord-depecated_finders This reverts commit dcff027a5242b20c0c90eb062dddb22ccf51aed9, reversing changes made to 3a2093984ff49d86db1efeff0c7581e788ecfb9f.
* Fix type cast on group sum with custom expressionPaul Nikitochkin2013-12-101-1/+3
| | | | | | | | For PG adapters with custom expression and grouped result of aggregate functions have not found correct column type for it. Extract column type from query result. Closes: #13230
* Stop accepting `options` for `Relation#average`, `Relation#minimum`, ↵Vipul A M2013-10-141-10/+10
| | | | `Relation#maximum`, `Relation#calculate`, `perform_calculation`, `NullRelation#calculate` as they isn't used anymore.
* `Relation#count` doesn't use options anymore.Vipul A M2013-10-131-3/+2
|
* Don't use Enumerable#next in pluck since it is very slowRyan Wallace2013-08-301-2/+1
|
* re-introduce `select_for_count` private method.Yves Senn2013-07-141-5/+10
| | | | See https://github.com/rails/rails/commit/da9b5d4a8435b744fcf278fffd6d7f1e36d4a4f2#commitcomment-3630064 for discussion.
* no need to to_sym the column name, leave it as-isAaron Patterson2013-07-021-1/+1
|
* avoid intermediate zipped arrayAaron Patterson2013-07-011-3/+2
|
* make the identity type a singleton to save on object creationAaron Patterson2013-07-011-3/+1
|
* only deal with strings internallyAaron Patterson2013-07-011-3/+3
|
* build an AST rather than slapping strings togetherAaron Patterson2013-07-011-11/+7
|
* stop exposing the underlying alias datastructureAaron Patterson2013-07-011-4/+4
|
* Remove deprecated `:distinct` option from `Relation#count`.Yves Senn2013-07-011-5/+0
|
* Simplify/fix implementation of default scopesJon Leighton2013-06-281-9/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation was necessary in order to support stuff like: class Post < ActiveRecord::Base default_scope where(published: true) scope :ordered, order("created_at") end If we didn't evaluate the default scope at the last possible moment before sending the SQL to the database, it would become impossible to do: Post.unscoped.ordered This is because the default scope would already be bound up in the "ordered" scope, and therefore wouldn't be removed by the "Post.unscoped" part. In 4.0, we have deprecated all "eager" forms of scopes. So now you must write: class Post < ActiveRecord::Base default_scope { where(published: true) } scope :ordered, -> { order("created_at") } end This prevents the default scope getting bound up inside the "ordered" scope, which means we can now have a simpler/better/more natural implementation of default scoping. A knock on effect is that some things that didn't work properly now do. For example it was previously impossible to use #except to remove a part of the default scope, since the default scope was evaluated after the call to #except.
* Remove fall back and column restrictions for `count`.Yves Senn2013-06-091-10/+6
|
* Merge pull request #10561 from Empact/nix-throwresultJon Leighton2013-06-071-2/+0
|\ | | | | Rather than raising ThrowResult when construct_limited_ids_conditions comes up empty, set the relation to NullRelation and rely on its results.
| * Rather than raising ThrowResult when construct_limited_ids_conditions comes ↵Ben Woosley2013-05-101-4/+0
| | | | | | | | | | | | up empty, set the relation to NullRelation and rely on its results. This will help avoid errors like 2fcafee250ee2, because in most cases NullRelation will do the right thing. Minor bonus is avoiding the use of exceptions for flow control.
| * Fix that #pluck wasn't rescuing ThrowResult, meaning it would blow up when ↵Ben Woosley2013-05-101-0/+2
| | | | | | | | failing to construct_limited_ids_condition.
* | Remove #sum with a block was deprecated.kennyj2013-06-011-9/+1
|/
* Handle aliased attributes in ActiveRecord::Relation.Godfrey Chan2013-05-011-8/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database: With the model class Topic alias_attribute :heading, :title end The call Topic.where(heading: 'The First Topic') should yield the same result as Topic.where(title: 'The First Topic') This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`. This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`. Github #7839 *Godfrey Chan*
* Prefer find_by over dynamic finders in rdocSam Ruby2013-04-021-1/+1
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-03-301-1/+1
|\ | | | | | | | | | | | | | | | | Conflicts: activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb activerecord/test/cases/adapter_test.rb guides/source/testing.md [ci skip]
| * Uniq cannot be used directly on an ActiveRecord model. 'DISTINCT field' is ↵Daniel Lobato2013-03-121-1/+1
| | | | | | | | the only pluck query that translates into the aforementioned SQL
* | Deprecate the `:distinct` option for `Relation#count`.Yves Senn2013-03-151-2/+7
| | | | | | | | | | | | | | We moved more and more away from passing options to finder / calculation methods. The `:distinct` option in `#count` was one of the remaining places. Since we can now combine `Relation#distinct` with `Relation#count` the option is no longer necessary and can be deprecated.
* | rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works.Yves Senn2013-03-151-2/+2
|/ | | | | | | | The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our Relation API is close to SQL terms I renamed `#uniq` to `#distinct`. There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue to work. I also updated the documentation to promote the use of `#distinct`.
* copy edits [ci skip]Vijay Dev2013-02-151-1/+1
|
* Add ActiveRecord.count documentation when used on group relationsMaurizio De Santis2013-02-071-0/+6
|
* `#count` in conjunction with `#uniq` performs distinct count.Yves Senn2013-01-261-1/+2
| | | | closes #6865
* Revert "Merge pull request #8989 from robertomiranda/use-rails-4-find-by"Guillermo Iguaran2013-01-181-1/+1
| | | | | This reverts commit 637a7d9d357a0f3f725b0548282ca8c5e7d4af4a, reversing changes made to 5937bd02dee112646469848d7fe8a8bfcef5b4c1.
* User Rails 4 find_byrobertomiranda2013-01-181-1/+1
|
* These are already required through AS/railsAkira Matsuda2013-01-071-2/+0
| | | | | | * dependencies/autoload * concern * deprecation
* warning removed: shadowing outer local variableArun Agrawal2012-12-301-2/+2
|
* fix time typcasting on group counts in PGAaron Patterson2012-12-281-2/+5
|
* mysql does not return alias names, so fall backAaron Patterson2012-12-281-4/+10
|
* fix PG typecasting errorsAaron Patterson2012-12-281-2/+5
|
* Cleans and removes useless 'Examples' tag [ci skip]Alvaro Pereyra2012-12-011-7/+2
|
* copy edits [ci skip]Vijay Dev2012-12-011-1/+1
|
* Fix Calculations#pluck doc to mention several attributes can be selected [ci ↵Florent Guilleux2012-12-011-3/+3
| | | | skip]