Me Ruby, You Jane
Let's make Ruby the king of the jungle...

Jamis harnessed SQL

Posted by Jon Gretar on November 09, 2006 at 08:47 PM

Jamis has a nice article on how to Harness SQL. I personally love ActiveRecord but I agree that you should use AR as much as you can, but trying to force all your work into AR even though it may not fit is a mistake.

def instantiate
  list = TodoList.create(:name => name, :description => description)

  TodoItem.connection.insert <<-SQL, "Populating items"
    INSERT INTO todo_items (todo_list_id, content, position, created_at)
      SELECT #{list.id}, content, position, UTC_TIMESTAMP()
        FROM todo_item_templates
       WHERE todo_list_template_id = #{id}
  SQL

  list.todo_items.reset
  list
end
Tags: ruby
Hierarchy: previous, next

Comments

There are 0 comments on this post. Post yours →

Post a comment

Required fields in bold.