Hello everyone,
I am racking my brain with a modelling question and can''t wrap my
around
the benefits of STI or Polymorphisms.
I am trying to model Questions and Answer behavior but I think I am not
using rails full power here.
I have (in simple terms)
Question
has_one Answer
Answer
belongs_to Question
I also have
Topic
has_many Posts
Post
belongs_to Topic
Now i am trying to make this really easy for me to Search, do specific
queries like "Give me all the Questions that Jim asked..." etc.
I tried using a polymorhpic association called Message that acts in
between these types so each time I create a new Message a end up
creating one of the Models above.
But then I ran into some open source code and saw an implementation that
used STI where they had a Message Model inheriting from a Communication
Model. I like this since the Question, Answer, Topic, Post, they all
share common things and it would be great to keep things DRY.
That got me thinking.
Is it wrong to do
class Communication < ActiveRecord:Base
end
class Message < Communication
end
class Question < Communication
end
class Answer < Communication
end
etc.
This way I could keep everything in one table but then I can''t do easy
things like Answer.find_all_by_id(5)
I think I am missing something about the behaviors here and would love
some help.
Thanks
Kent
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---