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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:52:28+00:00 2026-06-12T17:52:28+00:00

I am using Ruby on Rails v3.2.2. I have following associations with an alias_method

  • 0

I am using Ruby on Rails v3.2.2. I have following associations with an alias_method used for a has_many :through association, this way:

class Resource < ActiveRecord::Base
  has_many :article_associations
  alias_method :post_associations, :article_associations

  has_many :users, :through => :post_associations
end

When I execute the @article.users I get the following error:

ActiveRecord::HasManyThroughAssociationNotFoundError
Could not find the association :post_associations in model Article

Why it happens? Is there a way to make it to work as expected? That is, how to properly return @article.users through the “aliased” :post_associations?


Note: I would like to “state” / “use” the :post_associations in the has_many :users, :through => :post_associations statement because I am trying to “dynamically build” (that is, metaprogramming) the has_many :through association.


The Ruby on Rails Framework Trace is:

activerecord (3.2.2) lib/active_record/reflection.rb:501:in `check_validity!'
activerecord (3.2.2) lib/active_record/associations/association.rb:26:in `initialize'
activerecord (3.2.2) lib/active_record/associations/collection_association.rb:24:in `initialize'
activerecord (3.2.2) lib/active_record/associations/has_many_through_association.rb:10:in `initialize'
activerecord (3.2.2) lib/active_record/associations.rb:157:in `new'
activerecord (3.2.2) lib/active_record/associations.rb:157:in `association'
activerecord (3.2.2) lib/active_record/associations/builder/association.rb:44:in `block in define_readers'
...
  • 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-06-12T17:52:29+00:00Added an answer on June 12, 2026 at 5:52 pm

    I don’t see a reason why you need to alias_method name your association.

    Instead you could directly do something like this,

    class Resource < ActiveRecord::Base
      has_many :post_associations, :foreign_key => :resource_id, :class_name => "ArticleAssociation"
      has_many :users, :through => :post_associations
    end
    

    Another Solution

    class Resource < ActiveRecord::Base
      has_many :article_associations
      has_many :users, :through => :article_associations
    end
    
    def post_associations
      self.article_associations
    end
    

    you need to do either of this

    resource.post_associations
    

    or

    resource.article_associations
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ruby on Rails v3.2.2. I have following model classes class Country
I am using Ruby on Rails 3.2.2. I have the following scenario: # hash_params.class
I'm using ruby 1.9.2 and rails 3.2.2. I have a 'domain' model (domain.rb): class
I am using Ruby 1.9.2 and Ruby on Rails 3.2.2. I have following statements:
I am using Ruby 1.9.2 and Ruby on Rails 3.2.2. I have the following
I am using Ruby 1.8.7 and Rails 2.3.8 and I have the following root
Using Ruby 1.9.2, Rails 3.1. I have the following code: # review.rb def calculate_rating(reviewable)
I am using Ruby on Rails v3.0.9 and I have the following code in
I am using Ruby 1.9.2, Rails 3.1. I have the following: # review.rb def
I have created a blog application using Ruby on Rails which includes the ability

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.