Multiple Table Inheritance vs. Single Table Inheritance in Ruby on Rails

Posted by Tony on Stack Overflow See other posts from Stack Overflow or by Tony
Published on 2009-10-28T01:18:43Z Indexed on 2010/05/22 8:30 UTC
Read the original article Hit count: 367

I have been struggling for the past few hours thinking about which route I should go. I have a Notification model. Up until now I have used a notification_type column to manage the types but I think it will be better to create separate classes for the types of notifications as they behave differently.

Right now, there are 3 ways notifications can get sent out: SMS, Twitter, Email

Each notification would have:

id
subject
message
valediction
sent_people_count
deliver_by
geotarget
event_id
list_id
processed_at
deleted_at
created_at
updated_at

Seems like STI is a good candidate right? Of course Twitter/SMS won't have a subject and Twitter won't have a sent_people_count, valediction. I would say in this case they share most of their fields. However what if I add a "reply_to" field for twitter and a boolean for DM?

My point here is that right now STI makes sense but is this a case where I may be kicking myself in the future for not just starting with MTI?

To further complicate things, I want a Newsletter model which is sort of a notification but the difference is that it won't use event_id or deliver_by.

I could see all subclasses of notification using about 2/3 of the notification base class fields. Is STI a no-brainer, or should I use MTI?

Thanks!

© Stack Overflow or respective owner

Related posts about single-table-inheritance

Related posts about ruby-on-rails