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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:22:18+00:00 2026-05-18T00:22:18+00:00

I have the following model: class Advisor < ActiveRecord::Base belongs_to :course end class Course

  • 0

I have the following model:

class Advisor < ActiveRecord::Base
  belongs_to :course
end

class Course < ActiveRecord::Base
  has_many :advisors
  has_many :sessions
  has_many :materials, :through=>:sessions
end

class Session < ActiveRecord::Base
  belongs_to :course
  has_many :materials
end

class Material < ActiveRecord::Base
  belongs_to :session
end

I.e., every advisor teaches one course, every course has sessions, and every session has materials.
I want to traverse from an advisor to all the associated materials, i.e. something like: Advisor.first.materials
I tried to do:

class Advisor < ActiveRecord::Base
  belongs_to :course
  has_many :sessions, :through=>:course
  has_many :materials, :through=>:sessions
end

But it didn’t work as it treated sessions as a many-to-many table: Unknown column 'sessions.advisor_id' in 'where clause': SELECT 'material'.* FROM 'materials' INNER JOIN 'sessions' ON 'materials'.session_id = 'sessions'.id WHERE (('sessions'.advisor_id = 1))

I then tried to do:

class Advisor < ActiveRecord::Base
  belongs_to :course
  has_many :materials, :through=>:course
end

In an attempt to have the association use the “materials” association in the “Course” model, but received:

ActiveRecord::HasManyThroughSourceAssociationMacroError: Invalid source reflection on macro :has_many :through for has_many :materials, :through=>:sessions.  Use :source to specify the source reflection.

Tried to use “sessions” as the source which was a nice try but made me receive only the sessions rather than the materials.

Any ideas if this is at all possible?
I’m using Rails 2.3.8 (perhaps time to upgrade?)

Thanks!
Amit

  • 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-18T00:22:18+00:00Added an answer on May 18, 2026 at 12:22 am

    I want to traverse from an advisor to
    all the associated materials

    Unless I’m missing something, using the associations specified in your first example, you can simply call materials on the associated course:

    a = Advisor.first
    materials = a.course.materials
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following model class Order < ActiveRecord::Base has_many :products, :through => :line_items
I have the following User model: class User < ActiveRecord::Base has_many :competences has_many :skills,
I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name
I have the following model, Purchase, on my Rails app: class Purchase < ActiveRecord::Base
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
Let's say I have the following model: class Contest: title = models.CharField( max_length =
I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)
Say I have the following in my models.py : class Company(models.Model): name = ...
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
I have following model: class UserProfile(models.Model): User profile model, cintains a Foreign Key, which

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.