4 ms·
I love Rails, but I strongly disagree with its philosophy of the DB as being just a dumb data store. Two things I would recommend. One, the book Enterprise Rai
by chanks 14y ago
I love Rails, but I strongly disagree with its philosophy of the DB as being just a dumb data store. Two things I would recommend.
One, the book Enterprise Rails. It's a few years old, so all the examples are from Rails 2, but the meat of it is about proper database design, including the stuff that Rails doesn't believe in (composite primary keys, foreign key constraints, check constraints, triggers). Chapter 4, about the importance of data integrity, was probably the single most useful thing I've read about web development in the past few years.
Most of it is on Google Books (although sadly, chunks of chapter 4 are missing): http://books.google.com/books?id=thTju-4duY4C&printsec=frontcover http://books.google.com/books?id=thTju-4duY4C&printsec=f...
Second, the best thing I did was replace ActiveRecord with Sequel. Sequel has built-in support for all of those things that ActiveRecord doesn't (I couldn't live without its composite primary key support), and is in general a much more robust library than ActiveRecord. It also supports more exotic SQL features like CTEs and CASE statements without forcing you to drop down to writing raw SQL (though you can certainly do that if you want).
It's not a necessary upgrade for everyone. If your app has fairly simple models and relationships, ActiveRecord will probably be just fine for you. But if you want to get better with SQL and get closer to your DB, I think Sequel is a much better choice.
More info on Sequel: http://sequel.rubyforge.org/ http://sequel.rubyforge.org/
It also integrates very well with Postgres - there's a C extension for the Sequel postgres adapter (https://github.com/jeremyevans/sequel_pg https://github.com/jeremyevans/sequel_pg) and support for adding common triggers in migrations, counter columns and whatnot (https://github.com/jeremyevans/sequel_postgresql_triggers https://github.com/jeremyevans/sequel_postgresql_triggers). It also supports the more exotic datatypes - hstore, arrays, even the json and range types that are coming in PG 9.2.
- damoncali 14y agoThis is overkill for someone looking to grow into intermediate relational database concepts.
- chanks 14y agoThat's nice to hear, I guess. I play with a lot of this stuff and still feel intermediate.
- bartonfink 14y agoWhat would you describe as intermediate relational database concepts?
- damoncali 14y agoBased on what the OP says he wants to build, I'd say things like joins, the out of the box many-to-many functionality, etc. Basically, how do you link your models together in a sane way. No need for ORM replacement. Just good SQL fundamental knowledge. http://sql.learncodethehardway.org/book/ http://sql.learncodethehardway.org/book/ would be a good start.