Skip to content

Instantly share code, notes, and snippets.

@mrzasa
Last active October 13, 2016 14:50
Show Gist options
  • Save mrzasa/c9583067d917ea8362655f202193eaf7 to your computer and use it in GitHub Desktop.
Save mrzasa/c9583067d917ea8362655f202193eaf7 to your computer and use it in GitHub Desktop.
ActiveRecord::AssociationRelation vs ActiveRecord::Associations::CollectionProxy
> user.devices.all.uniq.class
=> Device::ActiveRecord_AssociationRelation
# so that we can chain more AR methods
> user.devices.all.uniq.limit(1)
=> [Device]
> u.devices.uniq.class
=> Array
# so we can only work on array:
> user.devices.uniq.limit(1)
NoMethodError: undefined method `limit' for []:Array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment