Archive for the ‘ActiveRecord’ Category

Enumerable#sort

Wednesday, December 12th, 2007 Posted in ActiveRecord, Rails, Ruby | No Comments »

In Ruby, to sort a collection of Objects, the <=> method needs to be defined. Suppose we have the following: # has a field created_at, which is a datetime class Event < ActiveRecord::Base end Let's say we want to do the following: @events = Event.find(:all) @events.sort To ...

has_many :finder_sql

Monday, August 27th, 2007 Posted in ActiveRecord, SQL | 2 Comments »

SQL can be a beautiful thing. That being said, I do try to avoid using native SQL as much as possible when writing applications, because for non-DBA types, it really doesn't have the most readable syntax in the world. In ActiveRecord ...