1. 06 3月, 2018 1 次提交
    • F
      Fix dependence on has_one/belongs_to relationships · a286c32c
      Fernando Gorodscy 提交于
      When a class has a belongs_to or has_one relationship with dependent: :destroy
      option enabled, objects of this class should not be deleted if it's dependents
      cannot be deleted.
      
      Example:
      
          class Parent
            has_one :child, dependent: :destroy
          end
      
          class Child
            belongs_to :parent, inverse_of: :child
            before_destroy { throw :abort }
          end
      
          c = Child.create
          p = Parent.create(child: c)
      
          p.destroy
      
          p.destroyed? # expected: false; actual: true;
      
      Fixes #32022
      a286c32c
  2. 26 1月, 2018 1 次提交
  3. 25 7月, 2017 1 次提交
    • R
      Fix `warning: assigned but unused variable - comment` · 36b7f3ae
      Ryuta Kamizono 提交于
      ```
      % ARCONN=sqlite3 be ruby -w -Itest test/cases/associations/belongs_to_associations_test.rb -n test_multiple_counter_cache_with_after_create_update
      test/cases/associations/belongs_to_associations_test.rb:1181: warning: assigned but unused variable - comment
      Using sqlite3
      Run options: -n test_multiple_counter_cache_with_after_create_update --seed 49644
      
      .
      
      Finished in 0.114266s, 8.7515 runs/s, 17.5030 assertions/s.
      
      1 runs, 2 assertions, 0 failures, 0 errors, 0 skips
      ```
      36b7f3ae
  4. 21 7月, 2017 1 次提交
  5. 20 7月, 2017 1 次提交
  6. 19 7月, 2017 1 次提交
    • L
      Add test for fixed `counter_cache` double increment · 6137a4e8
      Lisa Ugray 提交于
      When an `after_create` callback did `update_attributes` on a record with
      multiple `belongs_to` associations with counter caches, even numbered
      associations would have their counters double-incremented. Fixes to
      `ActiveModel::Dirty` in 020abadf fixed this.
      
      This adds regression tests for this bug fixed incidentally in the other
      commit, which also removed the need for the workaround using
      @_after_create_counter_called.
      6137a4e8
  7. 16 7月, 2017 1 次提交
  8. 13 7月, 2017 1 次提交
  9. 02 7月, 2017 1 次提交
  10. 01 7月, 2017 1 次提交
  11. 29 6月, 2017 1 次提交
  12. 28 4月, 2017 1 次提交
  13. 17 3月, 2017 1 次提交
    • G
      Add :default option to belongs_to (#28453) · 73b86ac5
      George Claghorn 提交于
      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 }
      73b86ac5
  14. 30 12月, 2016 1 次提交
  15. 25 12月, 2016 1 次提交
  16. 10 12月, 2016 1 次提交
  17. 22 11月, 2016 1 次提交
    • Y
      Introduce `reload_<association>` reader for singular associations. · 0e995713
      Yves Senn 提交于
      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.
      0e995713
  18. 29 10月, 2016 1 次提交
  19. 10 10月, 2016 1 次提交
  20. 26 8月, 2016 1 次提交
    • J
      Don't unnecessarily load a belongs_to when saving. · a94fe297
      James Coleman 提交于
      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.
      a94fe297
  21. 16 8月, 2016 1 次提交
  22. 07 8月, 2016 2 次提交
  23. 13 5月, 2016 1 次提交
    • S
      Give more context from `AssociationMismatchError` · 0991c4c6
      Sean Griffin 提交于
      The error message that we give today makes this error difficult to debug
      if you receive it. I have no clue why we're printing the object ID of
      the class (the commit doesn't give context), but I've left it as it was
      deliberate.
      0991c4c6
  24. 29 4月, 2016 1 次提交
  25. 02 3月, 2016 1 次提交
  26. 17 12月, 2015 1 次提交
  27. 23 9月, 2015 1 次提交
  28. 27 8月, 2015 1 次提交
  29. 13 8月, 2015 1 次提交
  30. 17 7月, 2015 1 次提交
    • P
      Silence deprecation warning from force reload · b5b89796
      Prem Sichanugrist 提交于
      We deprecate the support for passing an argument to force reload in
      6eae366d. That led to several
      deprecation warning when running Active Record test suite.
      
      This commit silence the warnings by properly calling `#reload` on the
      association proxy or on the association object instead. However, there
      are several places that `ActiveSupport::Deprecation.silence` are used as
      those tests actually tests the force reload functionality and will be
      removed once `master` is targeted next minor release (5.1).
      b5b89796
  31. 16 7月, 2015 1 次提交
    • P
      Deprecate force association reload by passing true · 6eae366d
      Prem Sichanugrist 提交于
      This is to simplify the association API, as you can call `reload` on the
      association proxy or the parent object to get the same result.
      
      For collection association, you can call `#reload` on association proxy
      to force a reload:
      
          @user.posts.reload   # Instead of @user.posts(true)
      
      For singular association, you can call `#reload` on the parent object to
      clear its association cache then call the association method:
      
          @user.reload.profile   # Instead of @user.profile(true)
      
      Passing a truthy argument to force association to reload will be removed
      in Rails 5.1.
      6eae366d
  32. 22 6月, 2015 1 次提交
  33. 17 6月, 2015 1 次提交
  34. 14 6月, 2015 1 次提交
  35. 21 4月, 2015 1 次提交
    • A
      Rename association option :class to :anonymous_class · ac2b7a5c
      Andrew White 提交于
      In 1f006c an option was added called :class to allow passing anonymous
      classes to association definitions. Since using :class instead of
      :class_name is a fairly common typo even amongst experienced developers
      this can result in hard to debug errors arising in raise_on_type_mismatch?
      
      To fix this we're renaming the option from :class to :anonymous_class as
      that is a more correct description of what the option is for. Since this
      was an internal, undocumented option there is no need for a deprecation.
      
      Fixes #19659
      ac2b7a5c
  36. 09 4月, 2015 2 次提交
  37. 22 2月, 2015 1 次提交
  38. 27 1月, 2015 1 次提交