This project is archived and is in readonly mode.

#2292 ✓resolved
Yi

after_destroy callback is not triggered in call to collection_singular_id

Reported by Yi | March 18th, 2009 @ 07:53 PM | in 2.x

I have a salesperson model:


class Salesperson < User has_many :dealers_and_salespeople, :class_name => "DealerAndSalesperson"

def dealer=(dealer)

self.dealer_ids = dealer.nil? ? [] : [dealer.id]

end ...

end

The dealer_and_salesperson model is like this:


class DealerAndSalesperson < ActiveRecord::Base set_table_name "dealers_and_salespeople" belongs_to :salesperson belongs_to :dealer

after_create :create_event_22 after_destroy :create_event_24

def create_event_22

Event.create(:event_type_id => 22, :salesperson_id => salesperson_id, :dealer_id => dealer_id)

end

def create_event_24

Event.create(:event_type_id => 24, :salesperson_id => salesperson_id, :dealer_id => dealer_id)

end

end

When I call salesperson.dealer = an_existing_dealer, the after_create callback is triggered. But when I call salesperson.dealer = nil, the after_destroy callback is not triggered at all.

Please let me know if this is by design, or I'm not using rails in the right way.

Thanks, Yi Zhang

Comments and changes to this ticket

  • danny.chiu

    danny.chiu June 8th, 2009 @ 12:59 AM

    • Assigned user set to “DHH”

    I ran into the same question,the after_destroy callback did not work at all.
    My solution: changed after_destroy to before_destroy, and modified it. it worked finally!

  • David Trasbo

    David Trasbo April 14th, 2010 @ 08:14 PM

    • Assigned user changed from “DHH” to “Ryan Bigg”

    Yi,

    If this issue is still relevant I think you should try Danny's suggestion.

    Unless it turns out his suggestion doesn't fix the problem I think this ticket should be closed.

  • Ryan Bigg

    Ryan Bigg April 15th, 2010 @ 11:03 AM

    • State changed from “new” to “resolved”

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

Pages