This project is archived and is in readonly mode.

#947 ✓wontfix
Brennan Dunn

Fix options hash mutation in AssociationCollection

Reported by Brennan Dunn | August 31st, 2008 @ 11:30 PM | in 2.x

Reusing a hash of options for multiple finder queries on an association is problematic as the inputted options hash becomes mutated by #find. Attached patch simply dups the input to make the options hash recyclable.

@@@ruby options = { :order => 'updated_at desc' } Section.first.articles.find(:all, options) options # => => {:order=>"updated_at desc, created_at desc", :conditions=>"articles.section_id = 2", :limit=>nil, :select=>nil, :group=>nil, :joins=>nil, :readonly=>nil, :offset=>nil, :include=>:_route}


Comments and changes to this ticket

  • Brennan Dunn

    Brennan Dunn August 31st, 2008 @ 11:32 PM

    Messed up formatting.

    
    options = { :order => 'updated_at desc' }
    Section.first.articles.find(:all, options)
    options # => {:order=>"updated_at desc, created_at desc", :conditions=>"`articles`.section_id = 2", :limit=>nil, :select=>nil, :group=>nil, :joins=>nil, :readonly=>nil, :offset=>nil, :include=>:_route}
    
  • Pratik

    Pratik December 20th, 2008 @ 05:02 PM

    • State changed from “new” to “wontfix”

    This is the same behavior as AR::Base.find(). You should just call .dup yourself before you supply find() with a hash.

    Thanks.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages