0

My model reads as so :

class Registration < ActiveRecord::Base

  has_many :registered_courses
  has_many :courses,  through: :registered_courses
  has_many :sections, through: :courses

The problem is that if many different Registration's have the same Course. When I write something like :

Registration.find(x).sections

It returns sections from any registration with the same Course.

But what I really want is all sections only from that specific registration. That is, even if other Registrations are using the same Course.

Trip
  • 26,756
  • 46
  • 158
  • 277

1 Answers1

2

You can't get sections which belongs_to specific registration unless your section belongs to registration directly.

mpospelov
  • 1,510
  • 1
  • 15
  • 24
  • Ah ok that makes sense. So is there any alternative way to accomplish this though? – Trip Jun 25 '14 at 13:21
  • @Trip you can add usual relation has_many - belongs_to between registration and sections, and create relation when any event fired for example courses creation or any other, than you can get what you want. When you take has_many through association, rails work only one way: 1. it find through association models, 2. and then get target association. – mpospelov Jun 25 '14 at 19:50
  • I sort of understand your explanation, but can't visualize the code part.. I'll keep messing around. Thanks! – Trip Jun 26 '14 at 13:17