aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/autosave_association.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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.
| * Unset association when existing record is destroyed.James Coleman2012-03-021-0/+1
| | | | | | | | 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.
* | stop using class_attribute where methods/inheritance will suffice.Jon Leighton2012-07-131-10/+4
| |
* | CollectionProxy < RelationJon Leighton2012-05-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Merge pull request #3329 from armstrjare/autosave_collection_new_record_bugJosé Valim2012-03-181-1/+6
|\ \ | | | | | | Autosave association doesn't save all records on a new record for a collection association if there are records marked for destruction
| * | Fix bug with autosave collection association on new record with a marked for ↵Jared Armstrong2012-03-181-1/+6
| | | | | | | | | | | | destroy record in autosave collection.
* | | Updates 'modyfing' typo to 'modifying'Jonathan R. Wallace2012-03-171-1/+1
|/ /
* | Remove IdentityMapCarlos Antonio da Silva2012-03-131-6/+0
| |
* | Refactor and cleanup in some ActiveRecord modulesCarlos Antonio da Silva2012-03-031-16/+14
| | | | | | | | | | | | | | | | | | | | | | * 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
* | Revert "Remove meaningless code from the examples" of AutosaveAssociation Dimitar Dimitrov2012-02-221-0/+3
| | | | | | Reverts a part of 91148936f770dc8bbbb33d46a09528f1a32d8a71. Should probably be squashed with it when merging back in rails/rails.
* | Minor fixes to ActiveRecord::AutosaveAssociation's docs Dimitar Dimitrov2012-02-221-5/+3
|/ | | | * Fix typos * Remove meaningless code from the examples
* validate related records in the same validation context as parent.Emmanuel Oga2012-01-171-1/+1
| | | | | | | | | | | | | | | | | | | | 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. ```
* Remove Array.wrap calls in ActiveRecordRafael Mendonça França2012-01-061-2/+0
|
* Don't try to autosave nested assocs. Fixes #2961.Jon Leighton2011-12-141-1/+1
|
* added information about callbacks created by autosave association (#3639)Jakub Kuźma2011-11-281-4/+16
|
* Test case and fix for rails/rails#3450Jan Varwig2011-11-271-1/+1
| | | | Asssigning a parent id to a belongs_to association actually updates the object that is validated when the association has :validates => true
* Raise error when using write_attribute with a non-existent attribute.Jon Leighton2011-09-131-1/+4
| | | | | | | | | 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.
* Don't construct association scope in initializer. This yields a big ↵Jon Leighton2011-07-071-1/+1
| | | | performance gain for cases where the association is never used to load the target, for example with preloading. Related: #1873.
* Remove extra white spaces on ActiveRecord docs.Sebastian Martinez2011-05-231-1/+1
|
* Active Record typos.R.T. Lechow2011-03-051-1/+1
|
* Use proper objects to do the work to build the associations (adding methods, ↵Jon Leighton2011-02-211-15/+14
| | | | callbacks etc) rather than calling a whole bunch of methods with rather long names.
* Merge remote branch 'rails/master' into identity_mapEmilio Tagua2011-02-181-22/+26
|\ | | | | | | | | | | Conflicts: activerecord/lib/active_record/associations/association.rb activerecord/lib/active_record/fixtures.rb
| * Split AssociationProxy into an Association class (and subclasses) which ↵Jon Leighton2011-02-181-22/+26
| | | | | | | | manages the association, and a CollectionProxy class which is *only* a proxy. Singular associations no longer have a proxy. See CHANGELOG for more.
* | Merge remote branch 'rails/master' into identity_mapEmilio Tagua2011-02-151-18/+22
|\| | | | | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/examples/performance.rb activerecord/lib/active_record/association_preload.rb activerecord/lib/active_record/associations.rb activerecord/lib/active_record/associations/association_proxy.rb activerecord/lib/active_record/autosave_association.rb activerecord/lib/active_record/base.rb activerecord/lib/active_record/nested_attributes.rb activerecord/test/cases/relations_test.rb
| * Get rid of AssociationCollection#save_recordJon Leighton2011-02-141-1/+1
| |
| * just return the record from insert_record, use truthiness for comparisonsAaron Patterson2011-02-071-1/+3
| |
| * Rename AssociationProxy#loaded to loaded! as it mutates the associationJon Leighton2011-01-301-1/+1
| |
| * Allow assignment on has_one :through where the owner is a new record [#5137 ↵Jon Leighton2011-01-031-0/+1
| | | | | | | | | | | | | | | | | | | | state:resolved] This required changing the code to keep the association proxy for a belongs_to around, despite its target being nil. Which in turn required various changes to the way that stale target checking is handled, in order to support various edge cases (loaded target is nil then foreign key added, foreign key is changed and then changed back, etc). A side effect is that the code is nicer and more succinct. Note that I am removing test_no_unexpected_aliasing since that is basically checking that the proxy for a belongs_to *does* change, which is the exact opposite of the intention of this commit. Also adding various tests for various edge cases and related things. Phew, long commit message!
| * Rename AssociationReflection#primary_key_name to foreign_key, since the ↵Jon Leighton2010-12-311-3/+3
| | | | | | | | options key which it relates to is :foreign_key
* | Should save without validation if autosave is enabled.Emilio Tagua2010-12-201-2/+4
| |
* | Merge remote branch 'rails/master' into identity_mapEmilio Tagua2010-12-201-12/+10
|\| | | | | | | | | | | | | | | Conflicts: activerecord/lib/active_record/associations/association_proxy.rb activerecord/lib/active_record/autosave_association.rb activerecord/lib/active_record/base.rb activerecord/lib/active_record/persistence.rb
| * Only call save on belongs_to associations if the record has changed or any ↵Chiel Wester2010-12-161-1/+1
| | | | | | | | | | | | nested associations have changed (resolves #3353) Signed-off-by: José Valim <jose.valim@gmail.com>
| * Partialy revert f1c13b0dd7b22b5f6289ca1a09f1d7a8c7c8584bJosé Valim2010-11-281-7/+7
| |
| * fix typoRay Baxter2010-11-221-1/+1
| |