Skip to content

Instantly share code, notes, and snippets.

@jkongie
Created March 1, 2010 05:53
Show Gist options
  • Save jkongie/318112 to your computer and use it in GitHub Desktop.
Save jkongie/318112 to your computer and use it in GitHub Desktop.
Factory Girl - Polymorphic Factory
# Setting up a polymorphic factory for a join table
# Since rosterable is not the default name of the model we are calling, we can't use the convenience method
# that is used for area (f.association)
# All we have to do is fall back to the block way of doing it, calling f.rosterable and passing in the
# object you want to populate it with ( in this case a template). This will fill in both rosterable_id
# and rosterable_type for us
Factory.define(:template_rostered_area, :class => RosteredArea) do |f|
f.association :area
f.rosterable { |a| a.association(:template)}
end
@simonrentzke
Copy link

👍

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