From: Walton Hoops Date: 2010-06-08T08:40:10+09:00 Subject: Re: Looking for ORM for 'legacy' database. On 6/7/2010 4:05 PM, Dave Howell wrote: >> >> So assuming you already have a table named 'demos' in your database, you >> >> can just run 'script/generate model demo' and TADA! It works. >> >> >> > > Except that it didn't. I tried that, but I just ended up a bit sad and rather puzzled. > > > How did it not work? I guarantee something happened. My guess would that you didn't set the schema_search_path correctly in your 'config/database.yml' file so it couldn't find the table, but without an error message that is just a guess based on the kind of mistake I would make. > > > >> >> Or if you >> >> want, you can just create the demo.rb file in your app/models directory >> >> and that will work too. >> >> >> > > Er, OK. But **how**? Everything I've found just assumes I'll use the magic script command to make it. Nothing tells me "here's how you'd build one by hand, if you were so crazy that you'd want to do it that way." > > > You're probably right, everything assumes you will learn by following the tutorials or books, which believe it or not do show you how to edit those files manually. That said, all you need to put in that demo.rb file for the basic functionality is: class Demo < ActiveRecord::Base end Of course that assumes a few things, for example that you have a table named 'demos'. If you want to break that convention you'd have to look up how (in this case via :table_name function), but even using the magic scripts you'd have to look that up. >> >> As for UUIDs as PKs, you'll notice in the example above that I >> >> used strings as a PK with no difficulty. UUIDs should work the same way. >> >> >> > > I've thought so, too. But I just ended up with a whole lot of "Could not create table blahblahblah. Unrecognized data type UUID." messages in the file. I'd post it verbatim, but I'm afraid I've already wiped the test folder and de-installed Rails. > > > > > That is the kind of error you get running a database migration. Again, you DO NOT need to run ANY migrations to use Rails. It sounds to me like you never really understood how Rails actually worked and that's at least half the problem. That said there is nothing wrong with just writing a data access layer over your database (or using Sequel/ActiveRecord/GenericORMHere) and providing it to a web app written in Sinatra or something similar. In fact, given that you have a pre-existing database that likely violates many of Rails conventions that may be the best way to go. If you do decide to give Rails another look I'm sure you'll find plenty of people willing to help on the Rails list.