Skip to content

Instantly share code, notes, and snippets.

@jlindley
Created September 18, 2009 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlindley/189211 to your computer and use it in GitHub Desktop.
Save jlindley/189211 to your computer and use it in GitHub Desktop.
named_scope :multiple_per_zip, lambda{
zip_counts = Site.count(
:all, :group => 'addresses.zip', :joins => :addresses
)
multi_site_zip_counts = zip_counts.reject{|k,v| v < 2}
just_zips = multi_site_zip_counts.map{|pair| pair[0]}.compact
{:conditions => ['addresses.zip in (?)', just_zips.join(",")]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment