This project is archived and is in readonly mode.

#3288 ✓stale
Lawrence Pit

Using destroy on AR association collection updates the collection in memory.

Reported by Lawrence Pit | September 28th, 2009 @ 01:14 AM

This fails on the second +assert_equal+ statement.

  p = Pirate.first
  assert_equal 2, p.parrots.length
  assert_equal 1, p.parrots.length

Attached patch fixes this.

Comments and changes to this ticket

  • Prem Sichanugrist (sikachu)

    Prem Sichanugrist (sikachu) February 15th, 2010 @ 02:38 PM

    • State changed from “new” to “open”

    I somehow think that this is an intended behavior. Consider this snippet:

     $ parrot = Parrot.first
    => <Parrot id: 1, name: "Jack">
     $ parrot.destroy
    => <Parrot id:1, name: "Jack">
     $ parrot
    => <Parrot id:1, name: "Jack">

    Current behavior of p.parrots.destroy(p.parrots.first) would make it consistence with the above snippet, as it gives you the opportunity to access the record that was destroyed.

    Let's see how anybody else think about this idea.

  • Staszek

    Staszek February 16th, 2010 @ 01:06 PM

    I think it is not good idea to have access to destroyed record. You have to be very careful when you using it, but if you really want to have this destroyed object, it is easy to do this without making new data base query. If you would like to have updated collection after destroy you need to do db query or make some ugly workaround. Why I need update my collection? The best example is rendering ajax response. You have list of some objects(to-do list or something like that) on website. User clicks "remove object" and you would like to show its new list using ajax. For now you can not do this without making new db query after destroy.

  • Lawrence Pit

    Lawrence Pit February 16th, 2010 @ 11:37 PM

    So are you +1 on the patch? ;-)

    To me it's very simple: If one deletes something from a collection, then no one would expect it to be still part of that collection, right?

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:54 PM

    • Importance changed from “” to “”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:54 PM

    • State changed from “open” to “stale”

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>


Referenced by