1. 18 6月, 2014 1 次提交
    • S
      Don't save through records twice · 068f092c
      Sean Griffin 提交于
      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.
      068f092c
  2. 10 6月, 2014 1 次提交
  3. 27 5月, 2014 1 次提交
  4. 25 5月, 2014 1 次提交
  5. 21 5月, 2014 1 次提交
  6. 01 5月, 2014 1 次提交
  7. 11 4月, 2014 1 次提交
    • Y
      docs, make association `autosave: true` examples runnable. Closes #14700 · 856ffbe7
      Yves Senn 提交于
      [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.
      856ffbe7
  8. 26 3月, 2014 1 次提交
  9. 21 2月, 2014 1 次提交
  10. 09 2月, 2014 1 次提交
  11. 01 11月, 2013 1 次提交
  12. 25 10月, 2013 1 次提交
  13. 17 10月, 2013 2 次提交
  14. 23 7月, 2013 2 次提交
  15. 16 7月, 2013 1 次提交
  16. 03 6月, 2013 1 次提交
  17. 02 5月, 2013 1 次提交
    • J
      destroys association records before saving/inserting new association records · 483c301e
      Johnny Holton 提交于
      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.
      483c301e
  18. 19 4月, 2013 2 次提交
    • J
      Revert "Merge pull request #10183 from jholton/fix_association_auto_save" · 0920d4fc
      Jon Leighton 提交于
      This reverts commit e8727d37, reversing
      changes made to d098e1c2.
      
      Reason: it broke the mysql build
      0920d4fc
    • J
      destroys association records before saving/inserting new association records · 9de28419
      Johnny Holton 提交于
      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.
      9de28419
  19. 17 4月, 2013 1 次提交
  20. 03 4月, 2013 1 次提交
  21. 21 3月, 2013 1 次提交
  22. 26 2月, 2013 1 次提交
  23. 18 1月, 2013 2 次提交
  24. 02 12月, 2012 1 次提交
  25. 09 11月, 2012 1 次提交
  26. 14 7月, 2012 1 次提交
  27. 12 5月, 2012 1 次提交
    • J
      CollectionProxy < Relation · c86a32d7
      Jon Leighton 提交于
      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.
      c86a32d7
  28. 18 3月, 2012 1 次提交
  29. 17 3月, 2012 1 次提交
  30. 14 3月, 2012 1 次提交
  31. 03 3月, 2012 2 次提交
    • C
      Refactor and cleanup in some ActiveRecord modules · 50725cec
      Carlos Antonio da Silva 提交于
      * 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
      50725cec
    • J
      Unset association when existing record is destroyed. · 217a8b01
      James Coleman 提交于
      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.
      217a8b01
  32. 23 2月, 2012 2 次提交
  33. 17 1月, 2012 1 次提交
    • E
      validate related records in the same validation context as parent. · 9b15e01c
      Emmanuel Oga 提交于
      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.
      ```
      9b15e01c
  34. 06 1月, 2012 1 次提交