This post originated from an RSS feed registered with Ruby Buzz
by David Heinemeier Hansson.
Original Post: Answering a hibernated cry for mercy
Feed Title: Loud Thinking
Feed URL: http://feeds.feedburner.com/LoudThinking
Feed Description: All about the full-stack, web-framework Rails for Ruby and on putting it to good effect with Basecamp
informIT just started a new multiple-part tutorial on how to use Hibernate (the top dog in Java ORMs) to create a domain model for a small book shop. By the end of the second XML file, I was ready to cry for mercy. So I did and Active Record answered:
class Book < ActiveRecord::Base
belongs_to :publisher
has_and_belongs_to_many :authors
end
class Publisher < ActiveRecord::Base
has_many :books
end
class Author < ActiveRecord::Base
has_and_belongs_to_many :books
end
Whups. I think we just got ahead of ourselves. The model above won't materialize in the Hibernate tutorial for another few installments. For the first one, they just got Book up and running.
But since it took all of five seconds to describe the domain (please note that were assuming the existence of a database schema, just like the Hibernate tutorial), let's give a few examples on its usage as well:
This is not pseudo-code. It's how most of the domain logic in Basecamp and other Rails applications work. Why does it how to be harder than this?
If you're ready to get outta dodge, please do have a look at Rails. It's a web-application framework that includes Active Record and its sister Action Pack. I wouldn't recommend it if you're trying to make a living as a tutorials writer and you're paid by the word, though.