I am trying to make my image_maps get destroyed when either a product or image is deleted. Here is the code.
class ImageMap < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true
belongs_to :image
end
class Product < ActiveRecord::Base
has_many :image_maps, :as => :imageable
has_many :images, :through => :image_maps
end
class Image < ActiveRecord::Base
has_many :image_maps, :as => :imageable, :dependent => :destroy
end
Right now the image_maps do not get destroyed when you delete an image and i still need to figure out how to get it to work for products too.