Create Rails ActiveRecord Models from DDL
Posted by Jim Morris on Wed May 24 23:20:00 -0700 2006
I had a database with about 60 tables in it, most where simple lookup tables with simple has_many and belongs_to relationships, and I didn't want to manually create all the models, with the associations by hand. I googled around and came across Bill Katz's dbmodel, which takes the output of dbdesigner and creates the models with the relationships. However I already had the Databases and schema setup, and I didn't have (and couldn't find) a copy of dbdesigner to use. So I hacked Bills dbmodel to read a DDL file that was created from the command rake db:structure:dump, as I was using Postgresql this file had all the relevant relationship info in it plus a bit extra.
I added the ability to create the relationships that had non standard table names and foreign keys, and also added some validations to the created models.
... Show more ...