Skip to content

Instantly share code, notes, and snippets.

@leepfrog
Created June 19, 2014 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leepfrog/0bfb1371cc829cca67c4 to your computer and use it in GitHub Desktop.
Save leepfrog/0bfb1371cc829cca67c4 to your computer and use it in GitHub Desktop.
class Author < ActiveRecord::Base
has_one :history, as: :related
end
class History < ActiveRecord::Base
belongs_to :related, polymorphic: true
validates :related_id, presence: true, uniqueness: {scope: :related_type}
validates :related_type, presence: true, uniqueness: true
end
# What i'd like to be able to do
a=Author.first
# Do this to unset the history -- stage it for deletion
a.history=nil
# Purges the history object at this point
a.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment