Skip to content

Instantly share code, notes, and snippets.

@davetapley
Created July 29, 2013 00:13
Show Gist options
  • Save davetapley/6101402 to your computer and use it in GitHub Desktop.
Save davetapley/6101402 to your computer and use it in GitHub Desktop.
# Works, but a bit awkward:
def self.group_by_name(r)
r.group_by &:name
end
Model.group_by_name(models.where(..))
# Would be nicer to have
def self.group_by_name
group_by &:name
end
Model.where(..).group_by_name # but this gives: undefined method `group_by' for #<Class:'
@davetapley
Copy link
Author

I thought there was a method I could call which returns the chained relation, in the scope, on which I could call .to_a.group_by ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment