Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Callbacks when deleting self-referenced has_many?

Reply
Thread Tools

Callbacks when deleting self-referenced has_many?

 
 
Sven S.
Guest
Posts: n/a
 
      03-22-2010
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/.

 
Reply With Quote
 
 
 
 
Sven S.
Guest
Posts: n/a
 
      03-23-2010
Figured it out, I should be using the association callbacks. For some
odd reason, I've never needed them up until now:

http://guides.rubyonrails.org/associ...tion-callbacks
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting data from the file without deleting the file first crea C++ 2 12-28-2012 11:50 PM
Deleting a File from Hardrive and Deleting a SubKey in Registry Harry Barker C++ 2 04-19-2006 09:34 AM
Gridview, using Callbacks when Sorting and Paging ck388 ASP .Net 1 06-06-2005 09:55 PM
Problem using Client Side Callbacks in 2.0 =?Utf-8?B?TmV2ZXJseW4=?= ASP .Net 0 05-08-2005 04:10 AM
Client Side Callbacks for ASP.NET 1.x Lucas Tam ASP .Net 6 02-07-2005 01:41 PM



Advertisments