Skip to content

Instantly share code, notes, and snippets.

@almaron
Created June 25, 2014 15:30
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 almaron/601d5c22ab093dd9fee6 to your computer and use it in GitHub Desktop.
Save almaron/601d5c22ab093dd9fee6 to your computer and use it in GitHub Desktop.
class Message < ActiveRecord::Base
validates_presence_of :user_id, :head, :text
belongs_to :user
has_many :receivers, class_name: MessageReceiver, :dependent => :destroy
before_destroy :check_receivers
def check_receivers
if self.receivers.empty?
true
else
self.update(deleted: 1)
false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment