Skip to content

Instantly share code, notes, and snippets.

@dannytip
Forked from joshnesbitt/gist:306641
Created February 17, 2010 14:18
Show Gist options
  • Save dannytip/306647 to your computer and use it in GitHub Desktop.
Save dannytip/306647 to your computer and use it in GitHub Desktop.
# With macro
has_many :comments, :foreign_key => 'commentable_id', :conditions => "commentable_type = 'User'", :dependent => :destroy
# Without macro
def comments
Comment.all(:conditions => {:commentable_id => self.id, :commentable_type => 'User'})
end
before_destroy :remove_associated_comments
def remove_associated_comments
Comment.destroy_all({:commentable_id => self.id, :commentable_type => "User"})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment