aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/null_relation.rb
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Remove conditions parameter from `NullRelation#delete_all`Ryuta Kamizono2017-03-101-1/+1
| | | | Follow up of e7381d289e4f8751dcec9553dcb4d32153bd922b.
* Refactor `NullRelation#calculate`Ryuta Kamizono2016-11-161-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: ```ruby def calculate(operation, _column_name) if [:count, :sum].include? operation group_values.any? ? Hash.new : 0 elsif [:average, :minimum, :maximum].include?(operation) && group_values.any? Hash.new else nil end end ``` After: ```ruby def calculate(operation, _column_name) case operation when :count, :sum group_values.any? ? Hash.new : 0 when :average, :minimum, :maximum group_values.any? ? Hash.new : nil end end ```
* Remove unnecessary methods for `NullRelation`Ryuta Kamizono2016-07-291-29/+7
|
* Mutating the result of Relation#to_a should not affect the relationMatthew Draper2016-02-211-1/+1
| | | | | | Clarifying this separation and enforcing relation immutability is the culmination of the previous efforts to remove the mutator method delegations.
* File encoding is defaulted to utf-8 in Ruby >= 2.1Akira Matsuda2015-09-181-2/+0
|
* Fix NullRelation.update_all and .exists? signature to match the same on RelationBen Woosley2015-03-181-2/+2
|
* Optimize none? and one? relation query methods to use LIMIT and COUNT.Eugene Gilburg2015-02-121-0/+8
| | | | | | | | Use SQL COUNT and LIMIT 1 queries for none? and one? methods if no block or limit is given, instead of loading the entire collection to memory. The any? and many? methods already follow this behavior. [Eugene Gilburg & Rafael Mendonça França]
* Bring the implementation of Relation#or up to speedSean Griffin2015-01-281-5/+1
|
* Added #or to ActiveRecord::RelationMatthew Draper2015-01-281-0/+8
| | | | | | | Post.where('id = 1').or(Post.where('id = 2')) # => SELECT * FROM posts WHERE (id = 1) OR (id = 2) [Matthew Draper & Gael Muller]
* Remove support to activerecord-deprecated_findersRafael Mendonça França2015-01-021-3/+1
|
* Fixed a problem where `sum`, `size`, `average`, `minimum` and `maximum` usedKuldeep Aggarwal2014-05-151-3/+17
| | | | with a grouping was not returning a Hash.
* Changed the NullRelation so that when count is called with #group it will ↵Eric Chahin2014-04-161-2/+2
| | | | | | | properly return an empty hash instead of zero. Fixes issue #14721 Conflicts: activerecord/CHANGELOG.md
* Mark the arguments needed by activerecord-deprecated_finders with a TODORafael Mendonça França2013-12-111-2/+4
|
* Revert "Merge pull request #12518 from vipulnsward/remove_count_options"Rafael Mendonça França2013-12-111-1/+1
| | | | | | | It is needed for activerecord-depecated_finders This reverts commit dcff027a5242b20c0c90eb062dddb22ccf51aed9, reversing changes made to 3a2093984ff49d86db1efeff0c7581e788ecfb9f.
* Pluck on NullRelation accepts a list of columnsDerek Prior2013-10-151-1/+1
| | | | | | `pluck` was updated to accept a list of columns, but the `NullRelation` was never updated to match that signature. As a result, calling `pluck` on a `NullRelation` results in an `ArgumentError`.
* Stop accepting `options` for `Relation#average`, `Relation#minimum`, ↵Vipul A M2013-10-141-1/+1
| | | | `Relation#maximum`, `Relation#calculate`, `perform_calculation`, `NullRelation#calculate` as they isn't used anymore.
* Removed where_values_hash from AR::NullRelationPaul Nikitochkin2013-09-281-4/+0
| | | | | | | | | | | | | | | | | | | In order to build associated records for owners which has not been saved need to get where values to use as default attributes. But for new record owner uses `ActiveRecord::NullRelation` which override `where_values_hash` to return empty hash stub. `where_values_hash` is not used to invoke any sql query, but good to build others chains (even will be never executed) like: ```ruby post = Post.new admin_comment = post.admin_comments.build assert_equal 'Admin', admin_comment.author ``` Closes #11376, #11676, #11675
* Make NullRelation a bit more like a real relation by returning 0 for ↵Ben Woosley2013-05-101-1/+5
| | | | #calculate(:count)
* No point in memoizing a simple literal string.Ben Woosley2013-05-101-1/+1
|
* Delegate all calculations to the scope.Jon Leighton2012-11-091-0/+4
| | | | | | | So that the scope may be a NullRelation and return a result without executing a query. Fixes #7928
* Nullify the relation at a more general level.Jon Leighton2012-11-091-1/+1
| | | | | | | | | | | | | | | This allows us to avoid hacks like the "return 0 if owner.new_record?" in #count (which this commit removes). Also, the relevant foreign key may actually be present even on a new owner record, in which case we *don't* want a null relation. This logic is encapsulated in the #null_scope? method. We also need to make sure that the CollectionProxy is not 'infected' with the NullRelation module, or else the methods from there will override the definitions in CollectionProxy, leading to incorrect results. Hence the nullify: false option to CollectionAssociation#scope. (This feels a bit nasty but I can't think of a better way.)
* improve NullRelation docs [ci skip]Vijay Dev2012-07-211-1/+0
|
* Fix typos and add nodocs to NullRelationOscar Del Ben2012-07-171-1/+1
|
* unused method argumentsAkira Matsuda2012-06-011-7/+6
|
* modulize AR::NullRelationAkira Matsuda2012-06-011-2/+2
| | | | now we can invoke previously added scope extension methods
* Override AR::Relation methods in NullRelation.Juanjo Bazán2012-04-111-0/+53
| | | So a NullRelation (Relation#none) is chainable with database methods.
* Added `none` query method to return zero records.Juanjo Bazán2012-01-311-0/+10
And added NullRelation class implementing the null object pattern for the `Relation` class.