# An implementation level question

**URL:** <https://www.ruby-forum.com/t/an-implementation-level-question/193110>\
**Category:** Rails\
**Created:** [August 11, 2010, 1:34pm UTC](https://www.ruby-forum.com/t/an-implementation-level-question/193110 "2010-08-11T13:34:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [August 11, 2010, 1:34pm UTC](https://www.ruby-forum.com/t/an-implementation-level-question/193110/1 "2010-08-11T13:34:37Z")

</div>

Hi  
I have a message model and message\_participants table.  
message\_participants table because same message goes to various  
recipients.  
Messaging between either company to users OR user to company. So an  
initial design of tables made like

## messages table

±------------------±-------------±-----±----±--------±---------------+  
| Field | Type | Null | Key | Default | Extra |  
±------------------±-------------±-----±----±--------±---------------+  
| id | int(11) | NO | PRI | NULL | auto\_increment |  
| subject | varchar(255) | YES | | NULL | |  
| message\_thread\_id | int(11) | YES | | NULL | |  
| message | text | YES | | NULL | |  
| company\_id | int(11) | YES | | NULL | |  
±------------------±-------------±-----±----±--------±---------------+

## message\_participants table

±--------------±-------------±-----±----±--------±---------------+  
| Field | Type | Null | Key | Default | Extra |  
±--------------±-------------±-----±----±--------±---------------+  
| id | int(11) | NO | PRI | NULL | auto\_increment |  
| direction\_in | tinyint(1) | YES | | NULL | |  
| direction\_out | tinyint(1) | YES | | NULL | |  
| type | varchar(255) | YES | | NULL | |  
| company\_id | int(11) | YES | | NULL | |  
| user\_id | int(11) | YES | | NULL | |  
| message\_id | int(11) | YES | | NULL | |  
±--------------±-------------±-----±----±--------±---------------+

```
Here about 'type' field I am not sure. My question is should I treat

```

message\_participants like STI or polymorphic? I can’t decide it.

Relation is

message has\_many message\_participants  
message\_participants belongs\_to message

```
    Please guide

```

Thanks  
Tom

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [August 11, 2010, 3:58pm UTC](https://www.ruby-forum.com/t/an-implementation-level-question/193110/2 "2010-08-11T15:58:48Z")

</div>

Tom M. wrote:

> Hi  
> I have a message model and message\_participants table.  
> message\_participants table because same message goes to various  
> recipients.  
> Messaging between either company to users OR user to company.  
> […]  
> Here about ‘type’ field I am not sure. My question is should I treat  
> message\_participants like STI or polymorphic? I can’t decide it.

STI: single-table _inheritance_. Does User inherit from Company, or  
Company from User? Probably not. So no inheritance is involved, and  
you probably want a polymorphic association.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
