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

  • SEARCH
  • Home
  • 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 4600998
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:45:46+00:00 2026-05-21T23:45:46+00:00

It would be nice if there was a more elegant way of doing this,

  • 0

It would be nice if there was a more elegant way of doing this, given these models:

@forum_topic = ForumTopic.find(1)
@forum_topic.forum_sub_topics.each do |fst|  #it would be nicer if one could just type @forum_topic.sub_topics.each...
  #
end

It seems redundant to have to include forum_ in front of sub_topics because I know I’m dealing with a forum_topic. I could change the name of the table/model to SubTopic but that is a bit generic and could possibly come up somewhere in the application. Is there a way to override the name of the methods created on ForumTopic for the has_many association?

Models:

class ForumTopic...
  has_many :forum_sub_topics
end

class ForumSubTopic...
end

Ah the answer is right here. Thanks! 🙂
http://guides.rubyonrails.org/association_basics.html

  • 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-21T23:45:47+00:00Added an answer on May 21, 2026 at 11:45 pm

    Try this:

    has_many :sub_topics, :class_name => "ForumSubTopic"
    

    Reference

    ActiveRecord::Associations::ClassMethods has_many – see under Options

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

Sidebar

Related Questions

Is there an Add-In or a setting? Would be nice...
I'm trying to find an elegant way to parse a string like: EVENT_TYPE(param1;param2; ...)
This is more of a UX issue than a real problem but it would
Is there a way in Python, to have more than one constructor or more
Would be nice if the Entity framework had the ADO.Net equivalent of DataRow.HasErrors. I'm
It would be nice if the GeoShape page included examples or the individual properties
It would be nice to use ember.js , data from git HEAD , since
I would like to present a scenario where it would be nice to: have
I'm new to mechanize in python and it would be nice if someone could
I have a ruby on rails application and it would be nice to see

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.