| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
| |
068f092ced8483e557725542dd919ab7c516e567 registered autosave callbacks
as `after_save` callbacks. This caused the regression described in #17209.
Autosave callbacks should be registered as `after_update` and
`after_create` callbacks, just like before.
This is a partial revert of 068f092ced8483e557725542dd919ab7c516e567.
Fixes #17209.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
Callback order in Active Record objects are important. Users should not
define callbacks before the association definition or surprising
behaviours like the described at #3798 will happen. This callback order
dependency is documented at https://github.com/rails/rails/blob/31bfcdc77ca0d8cec9b5fe513bdc6f05814dd4f1/activerecord/lib/active_record/associations.rb#L1222-1227.
This reverts #15728.
Fixes #16620.
|
|
|
|
|
|
|
| |
If the through record gets created in an `after_create` hook that is
defined before the association is defined (therefore after its
`after_create` hook) get saved twice. This ensures that the through
records are created only once, regardless of the order of the hooks.
|
|
|
|
|
|
| |
Instead of checking for `macro == :has_one` throughout the
codebase we can create a `has_one?` method to match the `belongs_to?`,
`polymorphic?` and other methods.
|
|
|
|
|
|
|
|
|
| |
After ad7b5efb55bcc2e0ccd3e7f22a81e984df8676d1, which changed how
has_an_belongs_to_many used to work, we start raising an error when
redefining the same has_an_belongs_to_many association. This commits fix
that regression.
[Fixes #14983]
|
|
|
|
|
|
|
|
|
| |
Fix habtm reflection
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/counter_cache.rb
activerecord/lib/active_record/reflection.rb
activerecord/test/cases/reflection_test.rb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
alan/only_save_changed_has_one_objects""
This reverts commit e94e6c27af495a2460c811bb506459f1428dec6b.
Conflicts:
activerecord/CHANGELOG.md
The original commit was reverted only to be safe since #14407 were reported.
We don't have any proof we added a regression with the original commit
so reverting it now will give us more problem.
Closes #14407
|
|\
| |
| |
| | |
Fixed custom validation context bug for child associations
|
|/
|
|
|
|
|
|
| |
associations were not being saved.
Fixes #13854.
[Eric Chahin, Aaron Nelson, & Kevin Casey]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
[ci skip]
The examples are written in a way you expect them to be executable.
However one snippet assumed there to be two comments when only one
was created above.
The defined models did not extend `ActiveRecord::Base`
The example used `comments.last.mark_for_destruction`. This does no
longer load the whole collection but just the last record. It is
then refetcht on subsequent calls to `last`. This breaks the example.
|
|
|
|
|
|
|
|
|
| |
This reverts commit 6e3ab3e15faf782f6a937ccf5574a4fb63e3e353, reversing
changes made to 39e07b64ce3f4bb55e60ba0266e677f8e4f4893a.
Conflicts:
activerecord/CHANGELOG.md
activerecord/test/cases/autosave_association_test.rb
|
|\
| |
| |
| |
| |
| |
| | |
Save has_one associations only if record has changes
Conflicts:
activerecord/CHANGELOG.md
|
| |
| |
| |
| |
| |
| | |
Prevents save related callbacks such as `after_commit` being
triggered when `has_one` objects are already persisted and have no
changes.
|
| |
| |
| |
| | |
This reverts commit 5e3d466d52fa4e9a42c3a1f8773a7c31da875e48.
|
|/ |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
| |
Closes #11450
|
|
|
|
|
|
|
|
| |
This behaviour doesn't actually make sense, the context of
the child should not be affected by the parent. See #10492.
This reverts commit 5f8274efe128ffeec8fa3179460f5167a078f007, reversing
changes made to 81e837e810460d066a2e5fc5a795366ec8ab2313.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
fixes bug introduced by #3329
These are the conditions necessary to reproduce the bug:
- For an association, autosave => true.
- An association record is being destroyed
- A new association record is being created.
- There is a unique index one of the association's fields.
- The record being created has the same value as the record being
destroyed on the indexed field.
Before, the deletion of records was postponed until after all
insertions/saves. Therefore the new record with the identical value in
the indexed field caused a non-unique value error to be thrown at the database
level.
With this fix, the deletions happen first, before the insertions/saves.
Therefore the record with the duplicate value is gone from the database
before the new record is created, thereby avoiding the non-uniuqe value
error.
|
|
|
|
|
| |
Emphasizing that without autosave option only new
records are saved and updated records are not saved
|
| |
|
| |
|
| |
|
|
|
|
|
| |
This reverts commit 637a7d9d357a0f3f725b0548282ca8c5e7d4af4a, reversing
changes made to 5937bd02dee112646469848d7fe8a8bfcef5b4c1.
|
| |
|
| |
|
| |
|
|\
| |
| |
| |
| | |
jcoleman/should-unset-association-when-an-existing-record-is-destroyed
Unset association when existing record is destroyed.
|
| |
| |
| |
| | |
To avoid foreign key errors (and invalid data) in the database, when a belongs_to association is destroyed, it should also be nil'd out on the parent object.
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This helps bring the interfaces of CollectionProxy and Relation closer
together, and reduces the delegation backflips we need to perform.
For example, first_or_create is defined thus:
class ActiveRecord::Relation
def first_or_create(...)
first || create(...)
end
end
If CollectionProxy < Relation, then post.comments.first_or_create will
hit the association's #create method which will actually add the new record
to the association, just as post.comments.create would.
With the previous delegation, post.comments.first_or_create expands to
post.comments.scoped.first_or_create, where post.comments.scoped has no
knowledge of the association.
|
|\ \
| | |
| | | |
Autosave association doesn't save all records on a new record for a collection association if there are records marked for destruction
|
| | |
| | |
| | |
| | | |
destroy record in autosave collection.
|
|/ / |
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
* Avoid double hash lookups in AR::Reflection when reflecting associations/aggregations
* Minor cleanups: use elsif, do..end, if..else instead of unless..else
* Simplify DynamicMatchers#respond_to?
* Use "where" instead of scoped with conditions hash
* Extract `scoped_by` method pattern regexp to constant
* Extract noisy class_eval from method_missing in dynamic matchers
* Extract readonly check, avoid calling column#to_s twice in persistence
* Refactor predicate builder, remove some variables
|
| |
| |
| | |
Reverts a part of 91148936f770dc8bbbb33d46a09528f1a32d8a71. Should probably be squashed with it when merging back in rails/rails.
|
|/
|
|
| |
* Fix typos
* Remove meaningless code from the examples
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
E.G.:
```ruby
class Parent < ActiveRecord::Base
has_one :child
validates_presence_of :name, :on => "custom_context"
validates_associated :child
end
class Child < ActiveRecord::Base
belongs_to :parent
validates_presence_of :name, :on => "custom_context"
end
p = Parent.new(:name => "Montoto", :child => Child.new)
p.valid?(:custom_context) # => Returns true, even though the child is not valid under the same context.
```
|
| |
|
| |
|
| |
|
|
|
|
| |
Asssigning a parent id to a belongs_to association actually updates the object that is validated when the association has :validates => true
|
|
|
|
|
|
|
|
|
| |
Previously we would just silently write the attribute. This can lead to
subtle bugs (for example, see the change in AutosaveAssociation where a
through association would wrongly gain an attribute.
Also, ensuring that we never gain any new attributes after
initialization will allow me to reduce our dependence on method_missing.
|