This is my User model and its Subscription :
# app/models/user.rb class User < ActiveRecord::Base has_many :subscriptions, :before_add => :cancel_subscriptions! def cancel_subscriptions!(new_subscription=nil) subscriptions.each(&:cancel!) end end # app/models/subscription.rb class Subscription < ActiveRecord::Base belongs_to :user end
so when i do some_user.subscriptions.create it does a callback :cancel_subscriptions! and then I'm happy. But then I Subscription.create :user => some_user callback does not seem to be called, and I'm sad, so very, very sad.
Is there a way to make sure that the callback is executed whenever a Subscription associated with User ?
PD: I would really like not to write :before_create in my Subscription model, because I think that canceling all signatures should be User responsibility of the model.
source share