| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
association saved in the callback
Related #18155, #26661, 268a5bb, #27434, #27442, and #28599.
Originally #18155 was introduced for preventing double insertion caused
by the after save callback. But it was caused the before save issue
(#26661). 268a5bb fixed #26661, but it was caused the performance
regression (#27434). #27442 added new record to `target` before calling
callbacks for fixing #27434. But it was caused double firing before save
callback (#28599). We cannot add new object to `target` before saving
the object.
This is improving #18155 to only track callbacks after `save`.
Fixes #28599.
|
|
|
|
|
| |
Since #28473 `uniq` is delegated to `records`, so `CollectionProxy#uniq`
is unnecessary.
|
|
|
|
|
|
|
| |
Extension methods should not delegate to `scope` to respect dirty
target on `CollectionProxy`.
Fixes #28419.
|
|
|
|
| |
Follow up of #28453.
|
|
|
|
|
|
|
|
|
|
|
| |
Use it to specify that an association should be initialized with a
particular record before validation. For example:
# Before
belongs_to :account
before_validation -> { self.account ||= Current.account }
# After
belongs_to :account, default: -> { Current.account }
|
|
|
|
|
|
|
|
| |
The `select` in `QueryMethods` is also an enumerable method.
Enumerable methods with block should delegate to `records` on
`CollectionProxy`, not `scope`.
Fixes #28348.
|
| |
|
|
|
|
|
|
| |
Reflections only use their own information to create a `join_keys`
object. This means that we can call `join_keys` on a reflection object
and have it be context-free.
|
| |
|
|
|
|
|
|
|
| |
Scopes can only ever be *not* reflection objects when they are passed in
to the Reflection constructor. Given this fact, we can eliminate is_a
checks and an intermediate array object by just asking the reflection
object for join scopes.
|
|
|
|
|
| |
I don't think we actually need this parameter anymore. Nobody seems to
be using it.
|
|
|
|
|
|
|
|
|
| |
I incorrectly changed behavior of `dup`. Reading the original issue I
thought that `dup` should retain the original contents of the record
and it's associations but it is in fact supposed to be a copy as if a
record had been reinitialized.
This reverts commit ca8c21df0fdbf1f03ba2f7fb16b39c3282dc1be0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In Rails 3.2 dupping a `CollectionProxy` would dup it's `load_target` as
well. That functionality has been broken since the release of Rails 4.0.
I hit this in an application upgrade and wondered why duplicating a
CollectionProxy and assigning it to a variable stopped working.
When calling `dup` on a `CollectionProxy` only the owner (ex.
topic) was getting duplicated and the `load_target` would remain in tact
with it's original object ID. Dupping the `load_target` is useful for performing
a logging operation after records have been destroyed in a method.
For example:
```
def transfer_operation
saved_replies = topic.replies
topic.replies.clear
saved_replies.each do |reply|
user.update_replies_count!
end
end
```
This change adds a `initialize_dup` method that performs a `deep_dup` on
the `@associatiation` so that the `load_target` is dupped as well.
Fixes #17117
|
|\
| |
| | |
Delegate to `scope` rather than `merge!` for collection proxy
|
| | |
|
| | |
|
| |
| |
| |
| | |
Because merging the association scope was removed.
|
| |
| |
| |
| |
| | |
`merge! association.scope(nullify: false)` is expensive but most methods
do not need the merge.
|
| |
| |
| |
| | |
Fixes #27666.
|
|\ \
| | |
| | | |
Reload `through_record` that has been destroyed in `create_through_record`
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
This is an alternative of #27714.
If `has_one :through` association has set `nil`, `through_record` is
destroyed but still remain loaded target in `through_proxy` until
`reload` or `reset` explicitly.
If `through_proxy` is not reset (remain destroyed (frozen) target),
setting new record causes `RuntimeError: Can't modify frozen hash`.
To prevent `RuntimeError`, should reload `through_record` that has been
destroyed in `create_through_record`.
|
|/ /
| |
| |
| | |
`PolymorphicReflection` needs to be custom for handling scope lambdas
|
| |
| |
| |
| | |
because Struct.new returns a Class, we just can give it a name and use it directly without inheriting from it
|
| |
| |
| |
| | |
(I personally prefer writing one string in one line no matter how long it is, though)
|
| |
| |
| |
| | |
Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
|
|\ \
| | |
| | | |
Avoid to call `set_inverse_instance` twice for `has_many` association
|
| | |
| | |
| | |
| | |
| | | |
`create`, `create!`, and `concat` in `has_many` association hits
`set_inverse_instance` twice. It is enough to hit only once.
|
| | |
| | |
| | |
| | |
| | | |
Simply we can do `target.pluck(reflection.association_primary_key)` if
`target` is loaded.
|
| | | |
|
| | | |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
This issue was introduced with d849f42 to solve #19782. However, we can
solve #19782 without causing the issue. It is enough to save only when
necessary.
Fixes #27338.
|
|/ /
| |
| |
| |
| |
| | |
Some methods were added to public API in
5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of
the public API.
|
|\ \
| |/
|/| |
Add a record to target before any callbacks loads the record
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
`append_record` was added at 15ddd51 for not double adding the record.
But adding `append_record` (checking `@target.include?(record)`) caused
performance regression #27434. Instead of checking not double adding the
record, add a record to target before any callbacks loads the record.
Fixes #27434.
|
| |
| |
| |
| |
| |
| | |
Follow up to 5b14129d8d4ad302b4e11df6bd5c7891b75f393c.
http://edgeapi.rubyonrails.org/classes/ActiveRecord/Attribute.html
|
| | |
|
|/ |
|
| |
|
|\
| |
| |
| |
| | |
kamipo/prevent_range_error_for_belongs_to_associations
Prevent `RangeError` for `belongs_to` associations
|
| |
| |
| |
| |
| |
| |
| |
| | |
Currently to access `belongs_to` associations raises a `RangeError` if
foreign key attribute has out of range value.
It should return a nil value rather than raising a `RangeError`.
Fixes #20140.
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| | |
Fixes casting of IDs to the data type of the association primary key,
rather than then the data type of the model's primary key. (Tests use a
string primary key on the association, rather than an int.)
Tests issue #20995
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
9c9fb19 changed the behaviour of the _ids= setters for associations to
raise an AssociationTypeMismatch when unknown IDs are given:
Class: <ActiveRecord::AssociationTypeMismatch>
Message: <"Developer(#43811860) expected, got NilClass(#16732720)">
This restores the original ActiveRecord::RecordNotFound exception with a
much clearer error message:
Class: <ActiveRecord::RecordNotFound>
Message: <"Couldn't find all Developers with 'id': (1, -9999) [WHERE \"contracts\".\"company_id\" = ?] (found 1 results, but was looking for 2)">
Fixes #25719
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This patch brings back the functionality of passing true to the
association proxy. The behavior was deprecated with #20888 and scheduled
for removal in Rails 5.1.
The deprecation mentioned that instead of `Article.category(true)` one
should use `article#reload.category`. Unfortunately the alternative does
not expose the same behavior as passing true to the reader
did. Specifically reloading the parent record throws unsaved changes and
other caches away. Passing true only affected the association.
This is problematic and there is no easy workaround. I propose to bring
back the old functionality by introducing this new reader method for
singular associations.
|
|\ \
| | |
| | |
| | |
| | | |
kamipo/respect_new_records_for_collection_proxy_distinct
Respect new records for `CollectionProxy#uniq`
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Currently if `CollectionProxy` has more than one new record,
`CollectionProxy#uniq` result is incorrect.
And `CollectionProxy#uniq` was aliased to `distinct` in a1bb6c8b06db.
But the `uniq` method and the `SELECT DISTINCT` method are different
methods. The doc in `CollectionProxy` is for the `SELECT DISTINCT`
method, not for the `uniq` method.
Therefore, reverting the alias in `CollectionProxy` to fix the
inconsistency and to have the both methods.
|
|\ \ \
| |/ /
|/| | |
Add missing `+` around a some literals.
|
| | |
| | |
| | |
| | |
| | |
| | | |
Mainly around `nil`
[ci skip]
|
| | |
| | |
| | |
| | |
| | |
| | | |
* Fixes TypeError when cache counter value equals nil
* Test case for counter cache on unloaded has_many association
|
|\ \ \
| | | |
| | | | |
Remove unnecessary `target.uniq.size` in `CollectionAssociation#size`
|