I have two models, User and Image.
class User < ActiveRecord::Base
has_many :images,:order => "created_at DESC", :dependent => :destroy, :conditions => "archive = 0"
def destroy
self.archive = 1
self.deleted_at = Time.now
self.save
end
end
class Image < ActiveRecord::Base
belongs_to :user , :counter_cache => true
def destroy
self.archive = 1
self.deleted_at = Time.now
self.save
end
end
Now if you see above code, I am overriding destroy call in a model. Not when user is deleting his account I want to trigger dependent => destroy call back so that i triggers destroy for Image.
PS: I dont want to use act_as_paranoid or some other plugins. I need to trigger dependent=> destroy as I have a very deep complex mapping something like:
User has_many images, has_many comments, has_many likes, has_many activities and some more 9 types of mappings and again deep maping etc.