# Implementing project management and event types

**URL:** <https://www.ruby-forum.com/t/implementing-project-management-and-event-types/193568>\
**Category:** Rails\
**Created:** [August 19, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/implementing-project-management-and-event-types/193568 "2010-08-19T19:54:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardsugg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@richardsugg](https://www.ruby-forum.com/u/richardsugg)\
**Post date:** [August 19, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/implementing-project-management-and-event-types/193568/1 "2010-08-19T19:54:02Z")

</div>

I am implemented a simple project management application. Each  
project has various events, and each event can be a different type.  
Some event information is common, such as name, start date, close  
date, and comments. I have a projects table which has\_many events.  
My plan is to have several sub-event tables, like event\_get\_access  
which will contain an event\_id field to link it to table events as  
well as information specific to a “get access” event (remote access,  
username, passwords, etc). Another event type might be “upgrade”  
which stores information about the server to be upgraded, etc.

So I have:

- a project which has\_many events
- events which belongs\_to :project
- sub-events which belong\_to :event

How do the subevents relate to event? An event will never have more  
than one subevent, but it may not have any of a particular subevent.

Thanks for your help on this?

---

<div class="post-metadata">

**Author:** ![richardsugg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@richardsugg](https://www.ruby-forum.com/u/richardsugg)\
**Post date:** [August 19, 2010, 7:59pm UTC](https://www.ruby-forum.com/t/implementing-project-management-and-event-types/193568/2 "2010-08-19T19:59:19Z")

</div>

May be my

---

<div class="post-metadata">

**Author:** ![richardsugg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@richardsugg](https://www.ruby-forum.com/u/richardsugg)\
**Post date:** [August 19, 2010, 8:02pm UTC](https://www.ruby-forum.com/t/implementing-project-management-and-event-types/193568/3 "2010-08-19T20:02:14Z")

</div>

may be my option wrong. if I do your project i will do this.

- a project which has\_many events
- events which belongs\_to :project  
event has\_one sub\_event

option II

- a project which has\_many events
- events which belongs\_to :project  
sub\_event has column “sub\_event\_id”. it just refer the sub\_event table

On Fri, Aug 20, 2010 at 12:57 AM, Sampath M.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![richardsugg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@richardsugg](https://www.ruby-forum.com/u/richardsugg)\
**Post date:** [August 19, 2010, 9:51pm UTC](https://www.ruby-forum.com/t/implementing-project-management-and-event-types/193568/4 "2010-08-19T21:51:43Z")

</div>

On 19 August 2010 18:52, richardsugg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So I have:
> 
> - a project which has\_many events
> - events which belongs\_to :project
> - sub-events which belong\_to :event
> 
> How do the subevents relate to event? An event will never have more  
> than one subevent, but it may not have any of a particular subevent.

Have you looked at Single Table Inheritance, which would allow  
multiple types of event all in one table (rather than have subevents  
of different types)?

Otherwise I think you could have  
Event  
has\_one :sub\_event\_type\_one  
has\_one :sub\_event\_type\_two  
and so on.

Then  
SubEventTypeOne  
belongs\_to :event  
etc.

It does not matter if a particular event does not have a particular  
type of subevent, if you try to access event.sub\_event\_type\_one and it  
does not have one then you will get nil

Colin

---

<div class="post-metadata">

**Author:** ![richardsugg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@richardsugg](https://www.ruby-forum.com/u/richardsugg)\
**Post date:** [August 23, 2010, 3:19pm UTC](https://www.ruby-forum.com/t/implementing-project-management-and-event-types/193568/5 "2010-08-23T15:19:17Z")

</div>

Sorry for the delay – I forgot to subscribe to the thread and didn’t  
realize I had responses until I checked manually.

I thought about STI, but it seems that I would have a very complex  
table. I did not realize, however, that I could include a bunch of  
has\_one statements – I assumed that since an event would have a  
particular subevent based on the event\_type, that the has\_one wouldn’t  
work. Since it will (just have to check for nil and know which  
event\_type I’m working with), I think your second opinion would work.

Thanks!
