aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/autosave_association.rb
Commit message (Collapse)AuthorAgeFilesLines
* Don't unnecessarily load a belongs_to when saving.James Coleman2016-08-261-1/+3
| | | | | | | | Previously, if the the association was previously loaded and then the foreign key changed by itself, a #save call would trigger a load of the new associated record during autosave. This is unnecessary and the autosave code (in that case) didn't use the loaded record anyways.
* modernizes hash syntax in activerecordXavier Noria2016-08-061-3/+3
|
* A small documentation fix about autosave associations [ci skip]Mehmet Emin İNAÇ2016-03-051-1/+1
|
* Fixed setting errors details on autosaved associationsWojciech Wnętrzak2015-10-281-3/+18
|
* Merge pull request #19686 from tsun1215/index_errorsSean Griffin2015-10-261-3/+9
|\ | | | | | | | | | | Errors can be indexed with nested attributes Close #8638
| * Errors can be indexed with nested attributesMichael Probber2015-04-171-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `has_many` can now take `index_errors: true` as an option. When this is enabled, errors for nested models will be returned alongside an index, as opposed to just the nested model name. This option can also be enabled (or disabled) globally through `ActiveRecord::Base.index_nested_attribute_errors` E.X. ```ruby class Guitar < ActiveRecord::Base has_many :tuning_pegs accepts_nested_attributes_for :tuning_pegs end class TuningPeg < ActiveRecord::Base belongs_to :guitar validates_numericality_of :pitch end ``` - Old style - `guitar.errors["tuning_pegs.pitch"] = ["is not a number"]` - New style (if defined globally, or set in has_many_relationship) - `guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]` [Michael Probber, Terence Sun]
* | applies new doc guidelines to Active Record.Yves Senn2015-10-141-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* | add missing `:nodoc:` for `AutosaveAssociation::ClassMethods` [ci skip]Yves Senn2015-10-141-1/+1
| |
* | Fix Punctuation in `AutosaveAssociation` RDocRobert Eshleman2015-08-201-2/+2
| | | | | | | | [ci skip]
* | Correctly ignore `mark_for_destruction` without `autosave`Sean Griffin2015-07-201-1/+1
| | | | | | | | | | | | | | | | | | As per the docs, `mark_for_destruction` should do nothing if `autosave` is not set to true. We normally persist associations on a record no matter what if the record is a new record, but we were always skipping records which were `marked_for_destruction?`. Fixes #20882
* | Ensure cyclic associations w/ autosave don't cause duplicate errorsSean Griffin2015-07-181-0/+7
|/ | | | | | | | | | | | | | | | This code is so fucked. Things that cause this bug not to replicate: - Defining the validation before the association (we end up calling `uniq!` on the errors in the autosave validation) - Adding `accepts_nested_attributes_for` (I have no clue why. The only thing it does that should affect this is adds `autosave: true` to the inverse reflection, and doing that manually doesn't fix this). This solution is a hack, and I'm almost certain there's a better way to go about it, but this shouldn't cause a huge hit on validation times, and is the simplest way to get it done. Fixes #20874.
* Always perform validations on nested attribute associationsSean Griffin2015-01-301-4/+12
| | | | | | | Collection associations would have already been validated, but singular associations were not. Fixes #18735.
* Fix potenital stack level too deep with autosave or validationMiklos Fazkeas2015-01-041-4/+11
| | | | | | | When associations checked for autosave have a cycle, and none of them is dirty, then changed_for_autosave? will be an infinite loop. We now remember if we're in the check and will short circuit the recursion.
* Deprecate `false` as the way to halt AR callbacksclaudiob2015-01-021-1/+1
| | | | | | | | | | Before this commit, returning `false` in an ActiveRecord `before_` callback such as `before_create` would halt the callback chain. After this commit, the behavior is deprecated: will still work until the next release of Rails but will also display a deprecation warning. The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
* Deprecate `false` as the way to halt AS callbacksclaudiob2015-01-021-1/+7
| | | | | | | | | | | | | | After this commit, returning `false` in a callback will display a deprecation warning to make developers aware of the fact that they need to explicitly `throw(:abort)` if their intention is to halt a callback chain. This commit also patches two internal uses of AS::Callbacks (inside ActiveRecord and ActionDispatch) which sometimes return `false` but whose returned value is not meaningful for the purpose of execution. In both cases, the returned value is set to `true`, which does not affect the execution of the callbacks but prevents unrequested deprecation warnings from showing up.
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-3/+3
|
* Autosave callbacks shouldn't be `after_save`Agis-2014-10-131-1/+3
| | | | | | | | | | | | 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.
* Use has_attribute?Rafael Mendonça França2014-09-171-1/+1
|
* Don't autosave unchanged has_one through recordsAlan Kennedy2014-09-151-1/+3
|
* Do not mark object as persisted after an association is savedRafael Mendonça França2014-09-051-2/+0
| | | | | | | | | | | 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.
* Don't save through records twiceSean Griffin2014-06-171-3/+2
| | | | | | | 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.
* add has_one? method and reuse instead of checking macroeileencodes2014-06-091-1/+1
| | | | | | 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.
* Fix redefine a has_and_belongs_to_many inside inherited classArthur Neves2014-05-271-24/+23
| | | | | | | | | 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]
* Merge pull request #15210 from arthurnn/fix_hbtm_reflectionArthur Neves2014-05-241-3/+5
| | | | | | | | | 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
* Revert "Revert "Merge pull request #8313 from ↵Rafael Mendonça França2014-05-201-2/+3
| | | | | | | | | | | | | | | 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
* Merge pull request #14924 from eric-chahin/issue_13854Matthew Draper2014-05-031-1/+2
|\ | | | | | | Fixed custom validation context bug for child associations
| * Fixed custom validation context bug where childEric Chahin2014-05-011-1/+2
|/ | | | | | | | associations were not being saved. Fixes #13854. [Eric Chahin, Aaron Nelson, & Kevin Casey]
* docs, make association `autosave: true` examples runnable. Closes #14700Yves Senn2014-04-111-6/+9
| | | | | | | | | | | | | | [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.
* Revert "Merge pull request #8313 from alan/only_save_changed_has_one_objects"Rafael Mendonça França2014-03-251-3/+2
| | | | | | | | | This reverts commit 6e3ab3e15faf782f6a937ccf5574a4fb63e3e353, reversing changes made to 39e07b64ce3f4bb55e60ba0266e677f8e4f4893a. Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/autosave_association_test.rb
* Merge pull request #8313 from alan/only_save_changed_has_one_objectsRafael Mendonça França2014-03-101-2/+3
|\ | | | | | | | | | | | | Save has_one associations only if record has changes Conflicts: activerecord/CHANGELOG.md
| * Save has_one associations only if record has changesAlan Kennedy2013-10-311-2/+3
| | | | | | | | | | | | Prevents save related callbacks such as `after_commit` being triggered when `has_one` objects are already persisted and have no changes.
* | Revert "context in validation goes through has many relationship"Aaron Patterson2014-02-201-1/+1
| | | | | | | | This reverts commit 5e3d466d52fa4e9a42c3a1f8773a7c31da875e48.
* | context in validation goes through has many relationshipKevin Casey2014-02-081-1/+1
|/
* Save association when primary key is manually setlaurocaetano2013-10-241-1/+7
|
* Fix some indentation on autosave associationArthur Neves2013-10-171-196/+196
|
* Make define_non_cyclic_method simplerArthur Neves2013-10-171-7/+7
|
* extend by adding relationships rather than monkey patchingAaron Patterson2013-07-221-6/+6
|
* decouple extensions from association object stateAaron Patterson2013-07-221-1/+1
|
* Do not re-save destroyed association on saving parent objectPaul Nikitochkin2013-07-151-0/+1
| | | | Closes #11450
* Revert "Merge pull request #4490 from EmmanuelOga/master"José Valim2013-06-041-1/+1
| | | | | | | | 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.
* destroys association records before saving/inserting new association recordsJohnny Holton2013-05-021-9/+8
| | | | | | | | | | | | | | | | | | | | | 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.
* without autosave option updated records not saveNeeraj Singh2013-04-171-1/+2
| | | | | Emphasizing that without autosave option only new records are saved and updated records are not saved
* Prefer find_by over dynamic finders in rdocSam Ruby2013-04-021-4/+4
|
* Update other counter caches on destroyIan Young2013-03-201-0/+14
|
* No need to send public methodsAkira Matsuda2013-02-261-1/+1
|
* Revert "Merge pull request #8989 from robertomiranda/use-rails-4-find-by"Guillermo Iguaran2013-01-181-4/+4
| | | | | This reverts commit 637a7d9d357a0f3f725b0548282ca8c5e7d4af4a, reversing changes made to 5937bd02dee112646469848d7fe8a8bfcef5b4c1.
* User Rails 4 find_byrobertomiranda2013-01-181-4/+4
|
* Cleans and removes 'Examples' tag [ci skip]Alvaro Pereyra2012-12-011-2/+0
|
* 1.9 hash syntax changesAvnerCohen2012-11-081-11/+11
|
* Merge pull request #5248 from ↵Jon Leighton2012-09-211-0/+1
|\ | | | | | | | | jcoleman/should-unset-association-when-an-existing-record-is-destroyed Unset association when existing record is destroyed.