Calling One Model From Another Model...

I use dependent destroy all the time but in this one case it is not enough. In my side model I want to be able to delete both the conversation and the “other side” of the conversation… problem is I am getting the following error:

uninitialized constant Side::Conversation

I can’t seem to understand why I am getting that error. Would great appreciate some feedback! :slight_smile: Code is below!

class Side < ActiveRecord::Base before_destroy :delete_conversation_and_other_side

belongs_to :conversation belongs_to :user belongs_to :with_user, :class_name => “User”, :foreign_key => “with_user_id” has_many :messages, :dependent => :destroy


def delete_conversation_and_other_side
  Side.destroy_all("with_user_id = #{self.user_id}")
  Conversation.delete_all("id = #{self.conversation_id}")


You should be able to get rid of the error by using self instead of Side. ie.

def delete_conversation_and_other_side   self.destroy_all("with_user_id = #{self.user_id}")   Conversation.delete_all("id = #{self.conversation_id}") end