Skip to content

Instantly share code, notes, and snippets.

@garethrees
Created September 13, 2012 14:52
Show Gist options
  • Select an option

  • Save garethrees/3714817 to your computer and use it in GitHub Desktop.

Select an option

Save garethrees/3714817 to your computer and use it in GitHub Desktop.
Rails Association CollectionProxy
# Ugh Rails Association CollectionProxy!
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/collection_proxy.rb
>> CountryProfile.all == Site.first.country_profiles
=> true
>> CountryProfile.all.count(:group => 'region')
=> 0
>> Site.country_profiles.count(:group => 'region')
=> #<OrderedHash {"Africa"=>4, "Asia"=>3, "Middle East/Eastern Europe"=>1, "Latin America"=>1}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment