| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|