Ok… I’ll add some more source code too…
class FeedSubscription < ActiveRecord::Base
belongs_to :user
belongs_to :feed
def before_destroy
puts “Destroying subscription id #{id}”
end
…
end
class User < ActiveRecord::Base
has_many :feed_subscriptions, :dependent => :destroy
…
end
u = User.create(:password=>“E”, :password_confirmation=>“E”, :email=>“E”)
=> #<User:0x33f4fb4 @new_record=false, @new_record_before_save=true,
@password=“E”, @attributes={“word_occurrences_count”=>0,
“salt”=>“272404100.524279319982906”, “name”=>nil, “look_for_words”=>[],
“hashed_password”=>“0056fef0f0b99b94644a138ee75bdcc60aa9ddcd”, “id”=>21,
“authors”=>{}, “time_zone”=>0, “prefs”=>{}, “email”=>“E”},
@errors=#<ActiveRecord::Errors:0x33f3e34 @errors={},
@base=#<User:0x33f4fb4 …>>, @password_confirmation=“E”>
FeedSubscription.count
=> 0
u.feed_subscriptions.create
=> #<FeedSubscription:0x33e8764 @new_record=false,
@attributes={“voted_positive”=>0, “standard_rating”=>0,
“posts_blocked”=>0, “id”=>18, “posts_served”=>0, “feed_id”=>nil,
“voted_negative”=>0, “user_id”=>21},
@errors=#<ActiveRecord::Errors:0x33e7cec @errors={},
@base=#<FeedSubscription:0x33e8764 …>>>
FeedSubscription.count
=> 1
u.destroy
=> #<User:0x33f4fb4 @feed_subscriptions=[#<FeedSubscription:0x33de548
@attributes={“voted_positive”=>“0”, “standard_rating”=>“0”,
“posts_blocked”=>“0”, “posts_served”=>“0”, “id”=>“18”, “feed_id”=>nil,
“voted_negative”=>“0”, “user_id”=>“21”}>], @feed_user_entries=[],
@new_record=false, @word_occurrences=[], @new_record_before_save=true,
@password=“E”, @attributes={“word_occurrences_count”=>0,
“salt”=>“272404100.524279319982906”, “name”=>nil, “look_for_words”=>[],
“hashed_password”=>“0056fef0f0b99b94644a138ee75bdcc60aa9ddcd”, “id”=>21,
“authors”=>{}, “time_zone”=>0, “prefs”=>{}, “email”=>“E”},
@errors=#<ActiveRecord::Errors:0x33f3e34 @errors={},
@base=#<User:0x33f4fb4 …>>, @password_confirmation=“E”>
FeedSubscription.count
=> 0
Everything looks ok there in the log above but the damn callback
function in FeedSubscription never gets called! The mongrel log that
normally would log stuff like that to doesn’t mention it either:
SQL (0.000532) INSERT INTO users (name
, salt
,
word_occurrences_count
, look_for_words
, hashed_password
,
authors
, time_zone
, prefs
, email
) VALUES(NULL,
‘272404100.524279319982906’, 0, ‘— []\n\n’,
‘0056fef0f0b99b94644a138ee75bdcc60aa9ddcd’, ‘— {}\n\n’, 0, ‘—
{}\n\n’, ‘E’)
SQL (0.010676) COMMIT
SQL (0.000552) SELECT count() AS count_all FROM feed_subscriptions
SQL (0.000258) BEGIN
SQL (0.000386) INSERT INTO feed_subscriptions (voted_positive
,
standard_rating
, posts_blocked
, posts_served
, feed_id
,
user_id
, voted_negative
) VALUES(0, 0, 0, 0, NULL, 21, 0)
SQL (0.009999) COMMIT
SQL (0.000556) SELECT count() AS count_all FROM feed_subscriptions
SQL (0.000262) BEGIN
FeedSubscription Load (0.001010) SELECT * FROM feed_subscriptions
WHERE (feed_subscriptions.user_id = 21)
FeedSubscription Destroy (0.000391) DELETE FROM feed_subscriptions
WHERE id
= 18
FeedUserEntry Load (0.000998) SELECT * FROM feed_user_entries WHERE
(feed_user_entries.user_id = 21)
WordOccurrence Load (0.000700) SELECT * FROM word_occurrences WHERE
(word_occurrences.user_id = 21)
User Destroy (0.000348) DELETE FROM users
WHERE id
= 21
SQL (0.010046) COMMIT
SQL (0.000537) SELECT count(*) AS count_all FROM feed_subscriptions