| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
| |
Follow up of e7381d289e4f8751dcec9553dcb4d32153bd922b.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
```
|
| |
|
|
|
|
|
|
| |
Clarifying this separation and enforcing relation immutability is the
culmination of the previous efforts to remove the mutator method
delegations.
|
| |
|
| |
|
|
|
|
|
|
|
|
| |
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]
|
| |
|
|
|
|
|
|
|
| |
Post.where('id = 1').or(Post.where('id = 2'))
# => SELECT * FROM posts WHERE (id = 1) OR (id = 2)
[Matthew Draper & Gael Muller]
|
| |
|
|
|
|
| |
with a grouping was not returning a Hash.
|
|
|
|
|
|
|
| |
properly return an empty hash instead of zero. Fixes issue #14721
Conflicts:
activerecord/CHANGELOG.md
|
| |
|
|
|
|
|
|
|
| |
It is needed for activerecord-depecated_finders
This reverts commit dcff027a5242b20c0c90eb062dddb22ccf51aed9, reversing
changes made to 3a2093984ff49d86db1efeff0c7581e788ecfb9f.
|
|
|
|
|
|
| |
`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`.
|
|
|
|
| |
`Relation#maximum`, `Relation#calculate`, `perform_calculation`, `NullRelation#calculate` as they isn't used anymore.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
| |
#calculate(:count)
|
| |
|
|
|
|
|
|
|
| |
So that the scope may be a NullRelation and return a result without
executing a query.
Fixes #7928
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.)
|
| |
|
| |
|
| |
|
|
|
|
| |
now we can invoke previously added scope extension methods
|
|
|
| |
So a NullRelation (Relation#none) is chainable with database methods.
|
|
And added NullRelation class implementing the null object pattern for the `Relation` class.
|