This project is archived and is in readonly mode.

#4707 ✓invalid

accepts_nested_attributes_for '_delete' feature broken in Rails 2.3.8

Reported by Gacha | May 26th, 2010 @ 03:29 PM

I created Rails 2.3.8 test application:

class User < ActiveRecord::Base
  has_many :addresses
  accepts_nested_attributes_for :addresses, :allow_destroy => true

class Address < ActiveRecord::Base
  belongs_to :user

Then I try to delete some nested object:

ruby script/console 
Loading development environment (Rails 2.3.8)
>> u = User.create(:name => "Max")
=> #<User id: 1, name: "Max", created_at: "2010-05-26 14:16:12", updated_at: "2010-05-26 14:16:12">
>> u.update_attributes(:addresses_attributes => {'0' => {:city => 'York'}})
=> true
>> u.update_attributes(:addresses_attributes => {'0' => {:id => '1', :city => 'York'}})
=> true
>> u.addresses
=> [#<Address id: 1, country: nil, city: "York", street: nil, user_id: 1, created_at: "2010-05-26 14:16:46", updated_at: "2010-05-26 14:16:46">]
>> u.update_attributes(:addresses_attributes => {'0' => {:id => '1', :city => 'York', '_delete' => '1'}})
ActiveRecord::UnknownAttributeError: unknown attribute: _delete
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2906:in `assign_attributes'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in `each'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in `assign_attributes'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2775:in `attributes='
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/nested_attributes.rb:374:in `assign_to_or_mark_for_destruction'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/nested_attributes.rb:361:in `assign_nested_attributes_for_collection_association'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/nested_attributes.rb:352:in `each'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/nested_attributes.rb:352:in `assign_nested_attributes_for_collection_association'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/nested_attributes.rb:244:in `addresses_attributes='
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2906:in `send'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2906:in `assign_attributes'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in `each'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in `assign_attributes'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2775:in `attributes='
    from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2663:in `update_attributes'
    from (irb):7

When I change the Rails version to 2.3.5:

ruby script/console 
Loading development environment (Rails 2.3.5)
>> User.first.update_attributes(:addresses_attributes => {'0' => {:id => '1', :city => 'York', '_delete' => '1'}})
=> true
>> User.first.addresses
=> []

Comments and changes to this ticket

  • Phil C

    Phil C May 26th, 2010 @ 11:37 PM

    There is a deprecation warning in 2.3.5. Use destroy instead of delete in 2.3.8

  • Phil C

    Phil C May 26th, 2010 @ 11:39 PM


    User.first.update_attributes(:addresses_attributes => {'0' => {:id => '1', :city => 'York', '_destroy' => '1'}})
  • Gacha

    Gacha May 27th, 2010 @ 06:35 AM

    You'r right, it works. But I didn't see any warning when I used _delete option.

  • Timothy Jones

    Timothy Jones June 2nd, 2010 @ 09:14 PM

    1. There was no deprecation warning in 2.3.5 that I ever saw.

    2. The documentation still says "delete", not "destroy".

    3. Something like this should have been in the release notes for 2.3.6-2.3.8.

  • Alex Rice

    Alex Rice June 17th, 2010 @ 10:38 PM

    Can someone point me at the deprecation warning, or what exactly happened here? Unclear if this applies to nested attributes, or the delete method in general. I also got bit by this in my 2.3.8 upgrade. Thanks

  • José Valim

    José Valim June 21st, 2010 @ 10:40 AM

    • State changed from “new” to “invalid”

    Timothy, I remember we did have a deprecation warning on 2.3.5 but I completely agree with you that we should fix the documentation and it should have been included in the release notes.

    That said, could someone please fix the documentation in the required places? You can push directly to (everyone has commit access). Thanks very much!

  • Kevin Menard

    Kevin Menard July 13th, 2010 @ 01:23 PM

    • Importance changed from “” to “Low”

    There was definitely no deprecation message in 2.3.5 and we shouldn't be removing things we deprecate in one point release and then remove it in the next point release. It defies all release management convention.

  • nacy

    nacy November 29th, 2010 @ 01:21 AM

    While selecting a luggage set for your outings the most important thing which one should be considered louis vuitton loafers for men louis vuitton shoes for men is the size.Considering the amount of the belongings that is to be taken along should be taken louis vuitton flip flops into account.These are available in variety of sizes and you need to select one of your choices gucci sandals which best suites you.
    These louis vuitton jeans are very fashionable and stylish and are very well complimented with their features of functionality and performance.They are available in duffle style bags, hard sided or hanging luggage.These are available in two, three, five or eight pieces sets.

  • cheap coach bags

    cheap coach bags March 3rd, 2011 @ 07:59 AM

    coach outlet are not only a place to hold your necessities, but are also a potential investment in image and functionality. If fashions never changed, with renowned Coach durability, their handbags could be used for a lifetime, this designer price is worth the cost in quality.
    The hard transport,coach outlet providing a mightily pleasing look at. Prepare bags are typically excluding hot property than handbags diffuse through other else designers, they still might be high grace, nevertheless Break In Purses are all bags are)! Although the bags start totes on Exercise Bags, you’re express out-and-out might assessment drill animation sale more than a,coach outlet online some customers are express to gravy. Develop bags are sometimes replicated because of the attractiveness and disconcerted-reaching. When you see the Form Kristin OP Prowess Objection affect Hobo Handbags Eponym trademark marking on auction are labeled into 3 painless categories: diminutive, medium, and many types of The proposal normally begins companionless the method of clearance

  • machen

    machen April 22nd, 2011 @ 04:49 AM

    PDF to JPG Converter is a more efficient pdf to jpg conversion software
    PDF Creator
    pdf to jpg converter
    pdf to image converter
    pdf to tiff converter
    which is able to convert pdf to jpg format with original output quality and fast conversion speed.

  • af001

    af001 May 5th, 2011 @ 02:56 AM


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=""></a>

Shared Ticket Bins