# Calling One Model From Another Model

**URL:** <https://www.ruby-forum.com/t/calling-one-model-from-another-model/129288>\
**Category:** Rails\
**Created:** [February 16, 2008, 5:03am UTC](https://www.ruby-forum.com/t/calling-one-model-from-another-model/129288 "2008-02-16T05:03:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [February 16, 2008, 5:03am UTC](https://www.ruby-forum.com/t/calling-one-model-from-another-model/129288/1 "2008-02-16T05:03:14Z")

</div>

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! 🙂 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

protected

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

```

end

–  
John K.  
removed\_email\_address@domain.invalid

Blog: [http://www.kopanas.com](http://www.kopanas.com)  
Conference: [http://www.cusec.net](http://www.cusec.net)  
Twits: [http://www.twitter.com/kopanas](http://www.twitter.com/kopanas)

---

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [February 16, 2008, 5:19pm UTC](https://www.ruby-forum.com/t/calling-one-model-from-another-model/129288/2 "2008-02-16T17:19:52Z")

</div>

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
