• 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
has_many_associations_test.rb 81.5 KB