Callbacks when deleting self-referenced has_many?

Discussion in 'Ruby' started by Sven S., Mar 22, 2010.

  1. Sven S.

    Sven S. Guest

    Hi

    I've come across a behavior which doesn't seem to be consistent. Let's
    assume the following models:

    class Client << ActiveRecord::Base
    has_many :resale_clients, :foreign_key => 'reseller_id'
    end

    class ResaleClient << Client
    belongs_to :client, :foreign_key => 'reseller_id'
    after_save :ack
    def ack
    puts "triggered"
    end
    end

    Now in the console (assuming two Client records exist in the db):

    >> c = Client.first
    >> r = ResaleClient.find(2)
    >> c.resale_clients << r # outputs "triggered"
    >> c.resale_clients.delete(r) # does not output "triggered"


    Any idea what I'm doing wrong here?

    Many thanks!!
    --
    Posted via http://www.ruby-forum.com/.
     
    Sven S., Mar 22, 2010
    #1
    1. Advertising

  2. Sven S.

    Sven S. Guest

    Sven S., Mar 23, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    630
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    630
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    433
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    406
    falcon
    Jul 31, 2005
  5. Bart Kastermans
    Replies:
    6
    Views:
    427
    Bart Kastermans
    Jul 13, 2008
Loading...

Share This Page