1. 02 12月, 2016 1 次提交
  2. 02 11月, 2016 1 次提交
    • S
      Deprecate the behavior of AR::Dirty inside of after_(create|update|save) callbacks · 16ae3db5
      Sean Griffin 提交于
      We pretty frequently get bug reports that "dirty is broken inside of
      after callbacks". Intuitively they are correct. You'd expect
      `Model.after_save { puts changed? }; model.save` to do the same thing as
      `model.save; puts model.changed?`, but it does not.
      
      However, changing this goes much farther than just making the behavior
      more intuitive. There are a _ton_ of places inside of AR that can be
      drastically simplified with this change. Specifically, autosave
      associations, timestamps, touch, counter cache, and just about anything
      else in AR that works with callbacks have code to try to avoid "double
      save" bugs which we will be able to flat out remove with this change.
      
      We introduce two new sets of methods, both with names that are meant to
      be more explicit than dirty. The first set maintains the old behavior,
      and their names are meant to center that they are about changes that
      occurred during the save that just happened. They are equivalent to
      `previous_changes` when called outside of after callbacks, or once the
      deprecation cycle moves.
      
      The second set is the new behavior. Their names imply that they are
      talking about changes from the database representation. The fact that
      this is what we really care about became clear when looking at
      `BelongsTo.touch_record` when tests were failing. I'm unsure that this
      set of methods should be in the public API. Outside of after callbacks,
      they are equivalent to the existing methods on dirty.
      
      Dirty itself is not deprecated, nor are the methods inside of it. They
      will only emit the warning when called inside of after callbacks. The
      scope of this breakage is pretty large, but the migration path is
      simple. Given how much this can improve our codebase, and considering
      that it makes our API more intuitive, I think it's worth doing.
      16ae3db5
  3. 29 10月, 2016 1 次提交
  4. 20 9月, 2016 1 次提交
    • R
      Always store errors details information with symbols · d406014b
      Rafael Mendonça França 提交于
      When the association is autosaved we were storing the details with
      string keys. This was creating inconsistency with other details that are
      added using the `Errors#add` method. It was also inconsistent with the
      `Errors#messages` storage.
      
      To fix this inconsistency we are always storing with symbols. This will
      cause a small breaking change because in those cases the details could
      be accessed as strings keys but now it can not.
      
      The reason that we chose to do this breaking change is because `#details`
      should be considered a low level object like `#messages` is.
      
      Fix #26499.
      
      [Rafael Mendonça França + Marcus Vieira]
      d406014b
  5. 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
  6. 07 8月, 2016 1 次提交
  7. 05 3月, 2016 1 次提交
  8. 29 10月, 2015 1 次提交
  9. 14 10月, 2015 2 次提交
    • Y
      applies new doc guidelines to Active Record. · 428d47ad
      Yves Senn 提交于
      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
      428d47ad
    • Y
  10. 21 8月, 2015 1 次提交
  11. 20 7月, 2015 1 次提交
    • S
      Correctly ignore `mark_for_destruction` without `autosave` · c0ef95a1
      Sean Griffin 提交于
      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
      c0ef95a1
  12. 18 7月, 2015 1 次提交
    • S
      Ensure cyclic associations w/ autosave don't cause duplicate errors · 7550f0a0
      Sean Griffin 提交于
      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.
      7550f0a0
  13. 18 4月, 2015 1 次提交
    • M
      Errors can be indexed with nested attributes · 21e448b5
      Michael Probber 提交于
      `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]
      21e448b5
  14. 30 1月, 2015 1 次提交
  15. 05 1月, 2015 1 次提交
  16. 03 1月, 2015 2 次提交
    • C
      Deprecate `false` as the way to halt AR callbacks · bb78af73
      claudiob 提交于
      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)`.
      bb78af73
    • C
      Deprecate `false` as the way to halt AS callbacks · d217daf6
      claudiob 提交于
      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.
      d217daf6
  17. 29 11月, 2014 1 次提交
  18. 13 10月, 2014 1 次提交
    • A
      Autosave callbacks shouldn't be `after_save` · 719d52db
      Agis- 提交于
      068f092c 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 068f092c.
      
      Fixes #17209.
      719d52db
  19. 18 9月, 2014 1 次提交
  20. 15 9月, 2014 1 次提交
  21. 06 9月, 2014 1 次提交
  22. 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
  23. 10 6月, 2014 1 次提交
  24. 27 5月, 2014 1 次提交
  25. 25 5月, 2014 1 次提交
  26. 21 5月, 2014 1 次提交
  27. 01 5月, 2014 1 次提交
  28. 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
  29. 26 3月, 2014 1 次提交
  30. 21 2月, 2014 1 次提交
  31. 09 2月, 2014 1 次提交
  32. 01 11月, 2013 1 次提交
  33. 25 10月, 2013 1 次提交
  34. 17 10月, 2013 2 次提交
  35. 23 7月, 2013 2 次提交
  36. 16 7月, 2013 1 次提交