Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:49:07+00:00 2026-05-30T17:49:07+00:00

In Rails 3.1, the documentation says 4.2.2.13 :source_type The :source_type option specifies the source

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:49:08+00:00Added an answer on May 30, 2026 at 5:49 pm

    :source_type deals with associations that are polymorphic. That is to say, if you have a relationship like this:

    class Tag < ActiveRecord::Base
      has_many :taggings, :dependent => :destroy
      has_many :books, :through => :taggings, :source => :taggable, :source_type => "Book"
      has_many :movies, :through => :taggings, :source => :taggable, :source_type => "Movie"
    end
    
    class Tagging < ActiveRecord::Base
      belongs_to :taggable, :polymorphic => true
      belongs_to :tag
    end
    
    class Book < ActiveRecord::Base
      has_many :taggings, :as => :taggable
      has_many :tags, :through => :taggings
    end
    
    class Movie < ActiveRecord::Base
      has_many :taggings, :as => :taggable
      has_many :tags, :through => :taggings
    end
    

    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'”

    tag = tag.find_by_name('Fun')
    tag.books
    

    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_type Informs 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails is a great platform, but it just doesn't have the history that Perl
A few months ago there was a feature in the Rails API documentation that
The documentation from rails generate controller says: [--helper] # Indicates when to generate helper
I have found that in all examples (include rails documentation) that I have seen
I've just started working with RubyPython, and though the documentation says you can load
I couldn't really find this in Rails documentation but it seems like 'mattr_accessor' is
I would like to read Rails documentation locally though gem server. I go to
I have been unable to find any documentation on the .build method in Rails
Rails gurus: I've just discovered named_scope thanks to another SO user. :) I'd like
I am trying to install vote-fu into my rails 3 project. The documentation (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.