aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/calculations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add test case for joined pluckSean Griffin2014-12-111-0/+7
| | | | https://github.com/rails/rails/commit/39542fba54328ca048fb75a5d5b37f8e1d4c1f37#commitcomment-8938379
* Improve the test case introduced by bd0d47eSean Griffin2014-12-111-19/+10
|
* Fix ProtocolViolation/bind message supplies for polymorphic + pluck or groupMiklos Fazkeas2014-12-111-0/+24
|
* Don't require calculations to be aliased to a columnSean Griffin2014-10-311-1/+0
| | | | | | | Arel has changed so that `.sum` no longer aliases `SUM(the_column)` to `sum_id`. This means the type returned by the adapter will be at the key `"SUM(the_column)"`. Longer term, we should eventually be able to retain type information from the AR::Base subclasses used in joined queries
* Move association definition to the model fileAkira Matsuda2014-08-281-2/+0
|
* Be sure that test fixtures satisfy referential integrity before calculatingAkira Matsuda2014-08-281-1/+1
| | | | | | | There exists some other test files that load :minivans fixtures but don't load :speedometers. Loading :speedometers here prevents the following error when this test was run after such test: CalculationsTest#test_should_group_by_association_with_non_numeric_foreign_key: ActiveRecord::RecordNotFound: Couldn't find all Speedometers with 'speedometer_id': (ABC, s1) (found 1 results, but was looking for 2)
* Don't use `Column` for type casting in Relation calculationsSean Griffin2014-06-181-5/+0
|
* Pluck should work with columns of the same name from different tablesSean Griffin2014-06-111-0/+7
| | | | | | | | The column name given by the adapter doesn't include the table namespace, so going through the hashed version of the result set causes overridden keys. Fixes #15649
* Rename `property` to `attribute`Sean Griffin2014-06-071-3/+3
| | | | For consistency with https://github.com/rails/rails/pull/15557
* Deprecate decimal columns being automatically treated as integersSean Griffin2014-05-271-0/+4
| | | | | | With ActiveRecord::Properties, we now have a reasonable path for users to continue to keep this behavior if they want it. This is an edge case that has added a lot of complexity to the code base.
* Ignore order when doing count.Lauro Caetano2014-04-071-0/+14
| | | | | | | This is necessary because Postgresql doesn't play nice with ORDER BY and no GROUP BY. Fixes #14621.
* Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes two regressions introduced in cafe31a078 where newly created finder methods #second, #third, #forth, and #fifth caused a NoMethodError error on reload associations and where we were pulling the wrong element out of cached associations. Examples: some_book.authors.reload.second # Before # => NoMethodError: undefined method 'first' for nil:NilClass # After # => #<Author id: 2, name: "Sally Second", ...> some_book.first.authors.first some_book.first.authors.second # Before # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 1, name: "Freddy First", ...> # After # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 2, name: "Sally Second", ...> Fixes #13783.
* Ensure #second acts like #first AR finderJason Meller2014-01-201-8/+10
| | | | | | | | | | | | This commit bring the famous ordinal Array instance methods defined in ActiveSupport into ActiveRecord as fully-fledged finders. These finders ensure a default ascending order of the table's primary key, and utilize the OFFSET SQL verb to locate the user's desired record. If an offset is defined in the query, calling #second adds to the offset to get the actual desired record. Fixes #13743.
* Fix type cast on group sum with custom expressionPaul Nikitochkin2013-12-101-0/+4
| | | | | | | | 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
* Change test_registering_new_handlers and test_count_on_invalid_columns_raisesYasuo Honda2013-08-021-1/+1
| | | | | tesetcases assertion to case insensitive because Oracle database adapter handles table name in uppercase.
* Remove deprecated `:distinct` option from `Relation#count`.Yves Senn2013-07-011-10/+0
|
* Remove fall back and column restrictions for `count`.Yves Senn2013-06-091-0/+9
|
* Merge pull request #10561 from Empact/nix-throwresultJon Leighton2013-06-071-0/+11
|\ | | | | Rather than raising ThrowResult when construct_limited_ids_conditions comes up empty, set the relation to NullRelation and rely on its results.
| * Add coverage for the fact that pluck without an argument returns all the ↵Ben Woosley2013-05-101-0/+5
| | | | | | | | table's columns.
| * Fix that #pluck wasn't rescuing ThrowResult, meaning it would blow up when ↵Ben Woosley2013-05-101-0/+6
| | | | | | | | failing to construct_limited_ids_condition.
* | Remove #sum with a block was deprecated.kennyj2013-06-011-6/+0
|/
* Handle aliased attributes in ActiveRecord::Relation.Godfrey Chan2013-05-011-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | 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*
* replace #merge with relation API calls in calculations_test.Yves Senn2013-04-021-17/+13
|
* Deprecate the `:distinct` option for `Relation#count`.Yves Senn2013-03-151-4/+14
| | | | | | | 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-1/+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`.
* `#count` in conjunction with `#uniq` performs distinct count.Yves Senn2013-01-261-0/+4
| | | | closes #6865
* fix PG typecasting errorsAaron Patterson2012-12-281-20/+7
|
* Deprecate Relation#sum with a block.Carlos Antonio da Silva2012-11-211-2/+4
| | | | | | | To perform a sum calculation over the array of elements, use to_a.sum(&block). Please check the discussion in f9cb645dfcb5cc89f59d2f8b58a019486c828c73 for more context.
* Revert "Yield only one argument instead of splatting."Carlos Antonio da Silva2012-11-211-16/+0
| | | | | | | | | | | | | | This reverts commit f9cb645dfcb5cc89f59d2f8b58a019486c828c73. Conflicts: activerecord/CHANGELOG.md Revert "Allow blocks for count with ActiveRecord::Relation. Document and test that sum allows blocks" This reverts commit 9cc2bf69ce296b7351dc612a8366193390a305f3. Conflicts: activerecord/lib/active_record/relation/calculations.rb
* `#pluck` can be used on a relation with `select` clause.Yves Senn2012-11-121-0/+6
| | | | Closes #7551
* remove unused variables. Oops!Aaron Patterson2012-10-171-2/+2
|
* use columns hash to look up the column for the count fieldAaron Patterson2012-10-171-13/+6
|
* ActiveRecord: sum expression returns string '0' for no records, fixedTim Macfarlane2012-10-151-0/+4
|
* Fix pluck when columns/tables are reserved words.Ian Lesperance2012-09-051-2/+9
|
* Remove ActiveRecord::Base.to_aJon Leighton2012-08-031-1/+1
| | | | | On reflection, it seems like a bit of a weird method to have on ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
* Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-271-13/+13
| | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* ActiveRecord::Base.all returns a Relation.Jon Leighton2012-07-271-1/+1
| | | | | | | | | | | Previously it returned an Array. If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This is more explicit. In most cases this should not break existing code, since Relations use method_missing to delegate unknown methods to #to_a anyway.
* Deprecate update_column in favor of update_columns.Rafael Mendonça França2012-07-241-2/+2
| | | | Closes #1190
* teaching the mysql adapter how to typecast strings returned from the databaseAaron Patterson2012-07-131-2/+2
|
* Ensure Arel columns are typecasted properly when grouping with calculationCarlos Antonio da Silva2012-06-251-3/+7
| | | | Fix build issue with postgresql.
* Stop assuming strings for grouped calculationsErnie Miller2012-06-241-0/+5
| | | | | | | | | | | | | | | Execute_grouped_calculation is one of those places where ActiveRecord forgets that it has ARel underpinnings, and assumes that the values provided to group_values are strings. This artificially hobbles otherwise functional code. This patch stops assuming that incoming values respond to to_sym, stops using string interpolation for table aliases on objects that support aliasing, and stops unnecessarily joining group_values on the relation. Additionally, it calls to_sql, if available, on objects sent to column_alias_for, in order to get a more reasonable alias string than a non-string's default to_str method.
* Refactor pluck with multiple columnsCarlos Antonio da Silva2012-06-221-10/+16
| | | | | | | | | | | | Ensure it works with mix of symbols and strings, and with a select clause possibly containing more than one column. Also remove support for pluck with an array of columns, in favor of passing the list of attributes: Model.pluck(:a, :b) See comments: https://github.com/rails/rails/pull/6500#issuecomment-6030292
* ActiveRecord#pluck now accepts multiple columnsjeroeningen2012-06-221-1/+16
|
* Extract conditional to a method to avoid duplicationRafael Mendonça França2012-06-191-0/+3
| | | | Also use if/else block to not use short circuit return
* handle joins/includes correctly for pluck and calculation.Andrey Deryabin2012-06-191-0/+43
| | | | Fix #5990
* Allow blocks for count with ActiveRecord::Relation. Document and test that ↵chrisfinne2012-05-281-0/+16
| | | | sum allows blocks
* MySQL returns "SUM(DISTINCT(credit_limit))" as the column name unlessAaron Patterson2012-05-161-1/+5
| | | | | an alias is provided. Without the alias, the column cannot be found and properly typecast.
* Fixes issue where SQL fragments prevented type casting based on column type.Erich Menge2012-05-161-0/+3
|
* Restore support for Model.pluck('sql fragment')Jeremy Kemper2012-05-151-0/+8
|
* Fix PR #6091Andrew White2012-04-301-1/+1
| | | | | | 1. ActiveRecord::Base is not ActiveRecord::Relation 2. The order of records from an SQL query is uncertain without an ORDER clause 3. Run your own tests when submitting a pull request