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 6881537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:07:13+00:00 2026-05-27T05:07:13+00:00

I have an Activity model. It belongs_to :parent, :polymorphic => true . Does Rails

  • 0

I have an Activity model. It belongs_to :parent, :polymorphic => true.

Does Rails use parent.class.name, parent.model_name or something else to populate the parent_type field?

I want a Presenter to behave like the parent object it wraps, and I need to override the right method.

Thanks.

  • 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-27T05:07:14+00:00Added an answer on May 27, 2026 at 5:07 am

    I’m working with Rails 3.0.7 right now, and the polymorphic type is being defined in active_record-3.0.7/lib/active_record/association.rb, line 1773.

    def create_belongs_to_reflection(association_id, options)
      options.assert_valid_keys(valid_keys_for_belongs_to_association)
      reflection = create_reflection(:belongs_to, association_id, options, self)
    
      if options[:polymorphic]
        reflection.options[:foreign_type] ||= reflection.class_name.underscore + "_type"
      end
    
      reflection
    end
    

    So it looks like it is calling class_name.underscore and then appending “_type”. This may be slightly different for rails 3.1, but this should be a good starting place.

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

Sidebar

Related Questions

I have a models in Django that are something like this: class Classification(models.Model): name
I have the following model: activity_types: id, name activities: id, id_activity_type, occurrences, date (other
I have a model called Activity in my django app. in the admin interface,
To provide an activity log in my SQLAlchemy-based app, I have a model like
I have this code: public class VoiceActivity extends Activity implements OnClickListener { private TextView
I have a Rails 2.3.11 app which has two key Models: Activity Transaction Live
I have defined a model class: public class MyObject { ... } In my
I am trying to use Windows Workflow and have a model that looks similar
In my Rails 3 project, I have a user model with a self referential
I have two models: Activity and Place. The Activity model has a ReferenceProperty to

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.