Skip to content

Instantly share code, notes, and snippets.

@kirkelifson
Created February 20, 2016 05:59
Show Gist options
  • Save kirkelifson/d08ccca26d1f234492ad to your computer and use it in GitHub Desktop.
Save kirkelifson/d08ccca26d1f234492ad to your computer and use it in GitHub Desktop.
Map relation containing id and model to instances
# Example:
# approvable_id = 7
# approval_type = "Finding"
# Finding.find(7) is yielded
Approval.pluck(:approvable_id, :approvable_type).sort.uniq.map { |id, type| Object.const_get(type).find(id) }.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment