In Rails 3.1, the documentation says
“4.2.2.13 :source_type
The :source_type option specifies the source association type for a has_one :through association that proceeds through a polymorphic association.
“
I just read :source explanation but still dont get what source_type is used for?
:source_typedeals with associations that are polymorphic. That is to say, if you have a relationship like this:Then the source type allows you to make queries like this:
“Find me all of the books that have been tagged with the tag named ‘Fun'”
Without source type, you wouldn’t be able to do that, you could only get a collection of objects that were tagged with ‘Fun’. If you only specificed source, it wouldn’t know which kind of class the objects were, so you it wouldn’t know which table in the DB to pull from. The
source_typeInforms it of which type of object you are trying to retreive.This is taken from this blog post: http://www.brentmc79.com/posts/polymorphic-many-to-many-associations-in-rails
Hope it helps.