| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
|
|
|
|
| |
Instead use .scope_attributes? consistently in ActiveRecord to check whether
there are attributes currently associated with the scope.
Move the implementation of .scope_attributes? and .scope_attributes to
ActiveRecord::Scoping because they don't particularly have to do specifically
with Named scopes and their only dependency, in the case of
.scope_attributes?, and only caller, in the case of .scope_attributes is
contained in Scoping.
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
| |
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]
|
|
|
|
|
|
|
|
|
| |
There are many ways that things end up getting passed to `concat`. Not
all of those entry points called `flatten` on their input. It seems that
just about every method that is meant to take a single record, or that
splats its input, is meant to also take an array. `concat` is the
earliest point that is common to all of the methods which add records to
the association. Partially fixes #18689
|
| |
|
|
|
|
| |
reference to past scope`
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
The records weren't being replaced since equality in Active Record is
defined in terms of `id` only. It is reasonable to expect that the
references would be replaced in memory, even if no queries are actually
executed. This change did not appear to affect any other parts of the
code base. I chose not to execute callbacks since we're not actually
modifying the association in a way that will be persisted.
Fixes #17730
|
|
|
|
|
|
|
|
| |
I grepped the source code for code snippets wrapped in backticks in the comments
and replaced the backticks with plus signs so they are correctly displayed in
the Rails documentation.
[ci skip]
|
|\
| |
| |
| |
| |
| |
| |
| |
| | |
Empact/association-bind-values-not-updated-on-save
Fix that a collection proxy could be cached before the save of the owner, resulting in an invalid proxy lacking the owner’s id
Conflicts:
activerecord/CHANGELOG.md
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
resulting in an invalid proxy lacking the owner’s id.
Absent this fix calls like: owner.association.update_all to behave unexpectedly because they try to act on association objects where
owner_id is null.
more evidence here: https://gist.github.com/Empact/5865555
```
Active Record 3.2.13
-- create_table(:firms, {:force=>true})
-> 0.1371s
-- create_table(:clients, {:force=>true})
-> 0.0005s
1 clients. 1 expected.
1 clients updated. 1 expected.
```
```
Active Record 4.0.0
-- create_table(:firms, {:force=>true})
-> 0.1606s
-- create_table(:clients, {:force=>true})
-> 0.0004s
1 clients. 1 expected.
0 clients updated. 1 expected.
```
|
| |
| |
| |
| |
| |
| | |
if you specify a default scope on a model, it will break caching. We
cannot predict what will happen inside the scope, so play it safe for
now. fixes #17495
|
|/
|
|
| |
follow up for #17052
|
|
|
|
|
|
| |
Eagerly loaded collection and singular associations are ignored by the StatementCache, which causes errors when the queries they generate reference columns that were not eagerly loaded.
This commit skips the creation of the StatementCache as a fix for these scenarios.
|
| |
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
When delete or destroy is called on all records nothing
is deleted or destroyed. Intead of running through the code and still
not deleteing anything, we should early return
|
|
|
|
|
|
|
| |
Rename delete_all_records because this name better describes
what the method is doing. We can then remove :all from the
hm:t version and pull out the unoptimized call to load_target
in delete_records and pass it directly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Refactor by creating two methods delete_all_records and delete_records
to be called by delete_all and delete (or destroy) respectively.
This reduces the number of conditionals required to handle _how_
records get deleted.
The new delete_count method handles how scope is applied to which
delete action.
A delete_all_records method also has to be called in has_many_through
association because of how the methods are chained. This will be
refactored later on.
|
|
|
|
|
|
|
|
| |
Now that delete_all with destroy or delete_all dependency behave
the same we no longer need this conditional. This means we can remove
the new delete_all_with_dependency method I added and go straight
to delete_records from delete_all, passing :all and the dependent
directly.
|
|
|
|
|
|
|
|
| |
Nullify (or nil dependency) was doing the same thing delete_all
was doing in issue #14546, creating a large IN statement if
the association was loaded. Loaded and not loaded associations
should behave the same. The IN statement is also not great because
it's inefficient.
|
|
|
|
|
|
|
| |
After reviewing this code I realized the conditional that was
there previously was basically saying if the dependency is not
delete all. This is a better, cleaner, and clearer way to write
this method.
|
|
|
|
|
| |
Now that we have a new method delete_all_with_dependency this
coupled conditional is no longer needed.
|
|
|
|
|
|
| |
The delete method is very coupled with delete all even
though only a portion of the conditionals apply. Decoupling
this will make the code easier to understand and manipulate.
|
| |
|
|
|
|
| |
SQL statements for querying associations are now cached
|
|
|
|
|
| |
Passing in a blank string is a bug so there's no reason
to check for a blank string.
|
|\
| |
| |
| | |
Renamed private methods _create_record and _update_record
|
| |
| |
| |
| |
| |
| | |
This is to ensure that they are not accidentally called by the app code.
They are renamed to _create_record and _update_record respectively.
Closes #11645
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When delete_all is run on a CollectionProxy and has a
dependency of delete_all the SQL that is produced has an IN
statement. (DELETE FROM `associated_model` where `associated_model`
.`parent_id` = 1 AND `associated_model`.`id` IN (1, 2, 3...)).
This only happens if the association is not loaded (both loaded
and non-loaded delete_all should behave the same. This is a huge
problem when it comes to deleting many records because the query
becomes very slow. Instead the SQL produced should be (DELETE FROM
`assoicated_model` where `associated_model`.`parent_model_id`=1).
I fixed this by making sure the check for loaded and destroy also
makes sure that the dependent is not delete_all, so the conditional
goes to the else and deletes the records directly without the IN
statement.
|
| | |
|
| |
| |
| |
| |
| | |
Pass the id of the object to the method by calling `.id` on the AR
object.
|
| |
| |
| |
| |
| |
| |
| | |
When replacing a has_many association with the same one, there is no
need to do a round-trip to the db to create/and drop a new transaction.
[fixes #14220]
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
`before_add` callbacks are fired before the record is saved on
`has_and_belongs_to_many` assocations *and* on `has_many :through`
associations. Before this change, `before_add` callbacks would be fired
before the record was saved on `has_and_belongs_to_many` associations, but
*not* on `has_many :through` associations.
Fixes #14144
|
|/
|
|
|
|
|
|
| |
constructor"
This reverts commit f9e4c3c7c0c4152b62fe9202a9d12262884bb118.
[fixes #14116]
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|\
| |
| |
| |
| | |
derikson/collection_proxy_select_with_multiple_args
Change CollectionProxy#select to take the same arguments as ActiveRecord::select
|
| |
| |
| |
| |
| |
| | |
arguments.
This makes the arguments the same as ActiveRecord::QueryMethods::select.
|
|\ \
| | |
| | | |
fix CollectionAssociation's comments
|
| | |
| | |
| | |
| | | |
AssociationProxy to match changes for 3.1 removing Association proxy.
|
| | | |
|
|/ /
| |
| |
| |
| |
| |
| | |
It is needed for activerecord-depecated_finders
This reverts commit dcff027a5242b20c0c90eb062dddb22ccf51aed9, reversing
changes made to 3a2093984ff49d86db1efeff0c7581e788ecfb9f.
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
was using nullify strategy
This caused a regression in applications trying to upgrade.
Also if the user set the dependent option as destroy he expects to get
the records removed from the database.
|
| | |
|
| | |
|
| |
| |
| |
| | |
.find([1]) should return an Array of entries, even when a invese object is in memory already
|
|\ \
| | |
| | |
| | |
| | |
| | |
| | | |
Fixed a bug in when using has_many association with :inverse_of option and UUID primary key.
Conflicts:
activerecord/CHANGELOG.md
|