i've started the work. i've been fixing up me schema a lot, and i've got some of the basic functions of the site up and running locally.
in a few days, i'll be ready to check the code into SVN or CVS and get some real development started.
yeah. that's the most important part. make sure your relationships are good. Also you should look into "Single Table Inheritance"
for example
class Topic
end
class ForumThread < Topic
end
class Journal < Topic
end
you'd have one table like:
CREATE TABLE `topics` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) default NULL,
`author_name` varchar(255) default NULL,
`written_on` datetime default NULL,
`content` text,
`type` varchar(50) default NULL,
PRIMARY KEY (`id`)
);
j = Journal.create(:title=> 'my journal', :author => 'me', :written_on => Date.new, :content => 'some content here')
would create a record in the 'topics' table with the 'type' field set to 'Journal'
Basically, you get and save Journal objects as if they were in their own table. And you can also get all Topics (be they Journals, ForumThreads or whatever) by performing operations on the supertype "Topic"
Topic.find(:conditions => ...)
ActiveRecord is a really really cool framework.
(I stole some of this from http://wiki.rubyonrails.com/rails/pages/Inheritance, which just happened to explain STI using a Topic and a Reply class.)
i definitely gotta do it that way!
i do it like that in the current Java code now, to a certain degree.
but if i clean up the schema a bit more, this could really shine.
yeah. I haven't looked at ezabel schema in a while, but I remember you doing something like this. But the difference in Rails is, its part of the ActiveRecord framework. good support for this kind of thing.
yeah that's really sexy. it figures out the type by the class name?
part of the problem is that I have different tables for everything
news, journals, threads, faqs, events.. all different tables.
i'm pretty sure i could merge news, journals, and threads. but some of the tables have columns specific to the type. i would have to either decide whether or not i really need the extra attributes, or just merge them all in. or have a child table by type or something.
yeah, that is a slight drawback to STI. it's illustrated here:
http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html
all properties of all classes in the inheritance tree are present in the table as fields.
but its not really a problem, as the unused fields are just left unpopulated.
yeah that works. sti helps with searching too.
So, i wrote a migration to create a topics table to merge news, forum_threads, and journals into one table. I combined all the columns. There's only a few that aren't shared, so that's not bad.
Got it working, seems pretty nice.
The only thing I'm wondering now is... do I need separate controllers for each of the models now? So much of the logic is the same, and I want to keep it DRY. Any ideas on sharing some of the logic?
Any chance any of us mortals could look at the schema? :) I'd really like to see how it's organized.
def. i'll have something to show you in a few days (after i'm done cleaning everything up).
the bad part is that i'm using MyISAM tables in MySQL instead of InnoDB. So, there's no foreign keys and no transactions right now.. works good enough though :)
here's the schema after a hefty clean-up. there's still a lot of cleanups to do, but it's much better than it was. i'll fix the remaining problems as i go.
/files/out.txt
you should be able to turn that into some Model classes pretty easily. at least with some of the relationships
Yeah. I've only made some of the models so far. Like, I've got the homepage working with news stories, and forums and threads all working. Comments come up in a basic layout (no threading yet). Login is (was) working. And Journals are working.
I haven't gone through and done much more than what the scaffolding provides for most parts, yet. Have to make the forms pretty, and fill in all the needed stuff on saves that shouldn't be entered by form.
I think my next step is to set up Migrations to make the db part easier.
loving Rails Migrations! ( http://media.rubyonrails.org/video/migrations.mov )
i've been evolving my schema a bit using the feature, and it really makes things nice.
yeah, that's one thing I hadn't looked into, but I probably should have on my rails project...