Created
January 30, 2013 00:20
-
-
Save patbenatar/4669415 to your computer and use it in GitHub Desktop.
Simple utility for working with polymorphic associations in ActiveRecord where queries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module PolymorphicQueryHelper | |
| class << self | |
| def expand_polymorphic_hash(hash) | |
| {}.tap do |expanded_hash| | |
| for name, object in hash | |
| expanded_hash.merge!({ | |
| "#{name}_id".to_sym => object.id, | |
| "#{name}_type".to_sym => object.class.name | |
| }) | |
| end | |
| end | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example:
is expanded to