News for hackers. Stuff that matters.
Re:Gotchas, Irritants and Warts in Go Web Development by lobster_johnson on Saturday March 09, 2013 @08:48PM (#5350350)
Hibernate is not a good example of an ORM, frankly. (I myself have horrors of both Hibernate and TopLink, which was the top Java ORM way back when.)

Ruby's ActiveRecord is a much better choice. It has an excellent balance between SQL and OO. It doesn't pretend that SQL doesn't exist; on the contrary, it encourgaes SQL use, and merely maps tables to objects, adds a bunch of useful features (data validation, change management, automatic joins, declarative migrations) and gets out of your way most of the time.

For example:

    users = User.where("created_at > ?", Time.now - 1.year).
      order('name').limit(10)
Results are lazily loaded and composable, so you can do:

    users = User.where("created_at > ?", Time.now - 1.year)
    if (page = params[:page])
      users = users.offset((page - 1) * 10).limit(10)
    end
Joining is easy:

    users = Users.joins(:accounts).
      where(accounts: {type: 'facebook')).first
becomes something like:

    select users.*
    from users
    join accounts on accounts.id = users.account_id
    where accounts.type = 'facebook'
    limit 1

There are no comments on this comment yet.