November 17, 2007

Little Things I love about Rails - This Time ActiveRecord

When you are setting a foreign key in an object you can do it using the id directly or through the helper method. In this example comments belong_to users.


# Using an object reference
u = User.get(1234)
c = Comment.new
c.user = u

# Old school
x = Comment.new
x.user_id = 1234

Yeah - that is what I like to see - a framework that respects programmer intelligence and gives us choices!

Posted by csev at November 17, 2007 08:03 AM