NICE
http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations
Looks like I should be able to do this:
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end
class Journal < ActiveRecord::Base
has_many :comments, :as => :commentable
end
Just have to rename generic_id and thread_type in the comments table to commentable_id and commentable_type, and do a quick update on the data to match the model names.
We'll see if it works!
Works great! I'm running a migration that puts the correct data into the 2 new columns. It's going to take hours... gotta find a faster way to do it. haha
Ok, that's better. 148 seconds to add the new columns, update them, and add the indexes. 270,000 rows in the comments table. Sheesh!
And it looks like I'll be able to take advantage of Single Table Inheritance for the three similar models (News, Journals, ForumThreads), and at the same time take advantage of the Polymorphic Association with :as => :commentable for all the various models that accept comments.
NICE
Yep, I found a bug. STI and Polymorphic Associations don't play together nicely all the time. nzkoz (rails core member) says it's a real live defect.
Details here http://rafb.net/paste/results/cVQNiO28.html
Ok, not a bug. Whew. This is good news.
Ian, have you ever been to another country and got to a meeting and even thou it is in a language you don't understand... you can still pick out the brother that is really into their talk, exuberant, excited about the information. I have no clue what your talking about here, but I AM HAPPY 4U!! :-)
haha, thanks for the encouragement :)
sweet. I think this started in rails 1.1 which I need to get up to speed on...