Skip to content

Instantly share code, notes, and snippets.

@kirkelifson
Created February 20, 2016 05:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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