Rails Multiple Table Inheritance question
Posted
by Tony
on Stack Overflow
See other posts from Stack Overflow
or by Tony
Published on 2009-10-28T21:46:01Z
Indexed on
2010/05/22
8:30 UTC
Read the original article
Hit count: 268
ruby-on-rails
I am starting to implement an MTI solution and have a basic question. I have 3 physical models - SMSNotifications, EmailNotifications, TwitterNotifications and they are subclasses of notification. At times in my code, I want to say Notifications.find(:all)
so that I can get a set of results sorted by their creation time. Then I want to do things based on their subclass. What is the way to write Notifications.find(:all)
and have Rails look through the subclass tables and combine the results? Right now Rails still thinks I have a physical Notifications table which goes against my MTI design.
I am also considering the possibility that I should be using STI instead. I would probably have 10 empty columns per row but if getting all notifications requires a query for each type of notification, then I feel like this could be a big issue.
Thanks!
© Stack Overflow or respective owner