Blogger.create { :name =>'Matt Aimonetti',
:location => 'San Diego, Ca',
:email => mattaimonetti AT gmail.com,
:linkedin => Matt's Linkedin page,
:recommend_me => HERE,
:contractor => true}

note to myself

Written by matt on May 11th, 2007

This morning I couldn't remember how to get an array with only the unique properties of a Model attribute. For instance, I have a User model, and I want to retrieve the list of all my users' cities. I also don't want to retrieve all the attributes and only the unique rows.

in my model:

def self.cities 
    User.find(:all, :select => "DISTINCT city").map(&:city)
end

Clean and simple, but for some reason I know I'll forget and loose 5 minutes trying different things.



Post a comment