1. 28 2月, 2017 1 次提交
    • E
      Dupping a CollectionProxy should dup the load_target · ca8c21df
      eileencodes 提交于
      In Rails 3.2 dupping a `CollectionProxy` would dup it's `load_target` as
      well. That functionality has been broken since the release of Rails 4.0.
      I hit this in an application upgrade and wondered why duplicating a
      CollectionProxy and assigning it to a variable stopped working.
      
      When calling `dup` on a `CollectionProxy` only the owner (ex.
      topic) was getting duplicated and the `load_target` would remain in tact
      with it's original object ID. Dupping the `load_target` is useful for performing
      a logging operation after records have been destroyed in a method.
      
      For example:
      
      ```
      def transfer_operation
        saved_replies = topic.replies
      
        topic.replies.clear
      
        saved_replies.each do |reply|
          user.update_replies_count!
        end
      end
      ```
      
      This change adds a `initialize_dup` method that performs a `deep_dup` on
      the `@associatiation` so that the `load_target` is dupped as well.
      
      Fixes #17117
      ca8c21df
  2. 04 1月, 2017 1 次提交
  3. 30 12月, 2016 3 次提交
  4. 25 12月, 2016 2 次提交
  5. 23 12月, 2016 1 次提交
    • R
      Add a record to target before any callbacks loads the record · 9eee7822
      Ryuta Kamizono 提交于
      `append_record` was added at 15ddd517 for not double adding the record.
      But adding `append_record` (checking `@target.include?(record)`) caused
      performance regression #27434. Instead of checking not double adding the
      record, add a record to target before any callbacks loads the record.
      
      Fixes #27434.
      9eee7822
  6. 03 12月, 2016 1 次提交
  7. 13 11月, 2016 1 次提交
    • R
      Respect new records for `CollectionProxy#uniq` · 0ec967aa
      Ryuta Kamizono 提交于
      Currently if `CollectionProxy` has more than one new record,
      `CollectionProxy#uniq` result is incorrect.
      
      And `CollectionProxy#uniq` was aliased to `distinct` in a1bb6c8b.
      But the `uniq` method and the `SELECT DISTINCT` method are different
      methods. The doc in `CollectionProxy` is for the `SELECT DISTINCT`
      method, not for the `uniq` method.
      
      Therefore, reverting the alias in `CollectionProxy` to fix the
      inconsistency and to have the both methods.
      0ec967aa
  8. 03 11月, 2016 1 次提交
  9. 29 10月, 2016 1 次提交
  10. 22 10月, 2016 1 次提交
  11. 30 9月, 2016 1 次提交
    • S
      Don't skip in-memory insertion of associations when loaded in validate · 268a5bb0
      Sean Griffin 提交于
      This was caused by 6d0d83a3. While the
      bug it's trying to fix is handled if the association is loaded in an
      after_(create|save) callback, it doesn't handle any cases that load the
      association before the persistence takes place (validation, or before_*
      filters). Instead of caring about the timing of persistence, we can just
      ensure that we're not double adding the record instead.
      
      The test from that commit actually broke, but it was not because the bug
      has been re-introduced. It was because `Bulb` in our test suite is doing
      funky things that look like STI but isn't STI, so equality comparison
      didn't happen as the loaded model was of a different class.
      
      Fixes #26661.
      268a5bb0
  12. 17 9月, 2016 1 次提交
  13. 16 8月, 2016 3 次提交
  14. 14 8月, 2016 2 次提交
  15. 07 8月, 2016 3 次提交
  16. 26 7月, 2016 2 次提交
  17. 20 7月, 2016 1 次提交
  18. 18 7月, 2016 1 次提交
  19. 19 5月, 2016 1 次提交
  20. 11 2月, 2016 1 次提交
  21. 10 2月, 2016 1 次提交
  22. 04 2月, 2016 1 次提交
  23. 23 11月, 2015 1 次提交
  24. 16 11月, 2015 1 次提交
    • Y
      Except keys of `build_record`'s argument from `create_scope` in initialize_attributes · 817c1825
      yui-knk 提交于
      If argument of `build_record` has key and value which is same as
      default value of database, we should also except the key from
      `create_scope` in `initialize_attributes`.
      Because at first `build_record` initialize record object with argument
      of `build_record`, then assign attributes derived from Association's scope.
      In this case `record.changed` does not include the key, which value is
      same as default value of database, so we should add the key to except list.
      
      Fix #21893.
      817c1825
  25. 21 10月, 2015 1 次提交
  26. 19 10月, 2015 1 次提交
    • J
      Reorder application of has_many association constraints. · d9bb13ba
      jbranchaud 提交于
      With `unscope!` called last, it undoes `where` constraints of the same
      value when the `where` is chained after the `unscope`. This is what a
      `rewhere` does. This is undesirable behavior.
      
      The included tests demonstrate both the `unscope(...).where(...)`
      behavior as well as the direct use of `rewhere(...)`.
      
      This is in reference to #21955.
      d9bb13ba
  27. 23 9月, 2015 1 次提交
  28. 12 9月, 2015 1 次提交
  29. 03 9月, 2015 1 次提交
    • B
      HasManyAssociation: moved half of counter cache code to reflection · 712fc8a5
      Bogdan Gusiev 提交于
      Current implementation has a lot of utility methods that accept
      reflection call a lot of methods on it and exit.
      
      E.g. has_counter_cache?(reflection)
      
      It causes confusion and inability to cache result of the method even
      through it always returns the same result for the same reflection
      object.
      It can be done easier without access to the association context
      by moving code into reflection itself.
      
      e.g. reflection.has_counter_cache?
      
      Reflection is less complex object than association so moving code there
      automatically makes it simplier to understand.
      712fc8a5
  30. 03 8月, 2015 1 次提交
  31. 24 7月, 2015 1 次提交
    • S
      `destroy` shouldn't raise when child associations fail to save · d937a117
      Sean Griffin 提交于
      Deep down in the association internals, we're calling `destroy!` rather
      than `destroy` when handling things like `dependent` or autosave
      association callbacks. Unfortunately, due to the structure of the code
      (e.g. it uses callbacks for everything), it's nearly impossible to pass
      whether to call `destroy` or `destroy!` down to where we actually need
      it.
      
      As such, we have to do some legwork to handle this. Since the callbacks
      are what actually raise the exception, we need to rescue it in
      `ActiveRecord::Callbacks`, rather than `ActiveRecord::Persistence` where
      it matters. (As an aside, if this code wasn't so callback heavy, it
      would handling this would likely be as simple as changing `destroy` to
      call `destroy!` instead of the other way around).
      
      Since we don't want to lose the exception when `destroy!` is called (in
      particular, we don't want the value of the `record` field to change to
      the parent class), we have to do some additional legwork to hold onto it
      where we can use it.
      
      Again, all of this is ugly and there is definitely a better way to do
      this. However, barring a much more significant re-architecting for what
      I consider to be a reletively minor improvement, I'm willing to take
      this small hit to the flow of this code (begrudgingly).
      d937a117