# Modeling an internal messaging system, how would you do?

**URL:** <https://www.ruby-forum.com/t/modeling-an-internal-messaging-system-how-would-you-do/167982>\
**Category:** Rails\
**Created:** [May 14, 2009, 5:07pm UTC](https://www.ruby-forum.com/t/modeling-an-internal-messaging-system-how-would-you-do/167982 "2009-05-14T17:07:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [May 14, 2009, 5:07pm UTC](https://www.ruby-forum.com/t/modeling-an-internal-messaging-system-how-would-you-do/167982/1 "2009-05-14T17:07:08Z")

</div>

Hey,

on my site, I’ve got an internal messaging system. A message can be  
saved, sender and recipient are saved as properties. Then, also one  
status number is saved, which indicates whether the message is sent/  
read/deleted either on the sender side or on the recipient side. As I  
relaunch the system, the question came to my mind, if I should it  
model another way. For example, I could associate the User and Message  
model over a intermediate model, where for example, I could save some  
more data, which refers directly to the relation. A message could then  
also have multiple recipient, for example, if I model the intermediate  
table 1:m.

There are many ways to do this, I think.

I just wanted to ask, how do you model this and why in this specific  
way?

Thank you very much,  
ms

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [May 14, 2009, 6:45pm UTC](https://www.ruby-forum.com/t/modeling-an-internal-messaging-system-how-would-you-do/167982/2 "2009-05-14T18:45:48Z")

</div>

I too would like to know if there is a conventional way of modeling  
this. I’m working on the same thing. For what it’s worth, I created  
two models: message-thread, and message. The message thread only  
carries the “subject” of the message, as I feel this doesn’t need to  
be stored with each individual message. Each subsequent message  
related to that subject is a child of the message-thread.

Good question. I’m looking forward to what others think.

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [May 15, 2009, 7:17pm UTC](https://www.ruby-forum.com/t/modeling-an-internal-messaging-system-how-would-you-do/167982/3 "2009-05-15T19:17:39Z")

</div>

I’ve used the restful\_ezm plugin with good results - the message model  
may be a little simplistic for some scenarios, but it works well most  
of the time. I’ve forked it and fixed a few issues (not correctly  
escaping boolean values in DB conditions, for instance) at:

> **[GitHub - al2o3cr/restful\_ezm: RESTful Easy Messages plug-in for Rails](https://github.com/al2o3cr/restful_ezm/tree/master)**
>
> master

It may be overkill for your app, as it also generates a default  
MessagesController, but could be of some inspiration.

–Matt J.
