How to populate join tables?


#1

Given:

class CseModule < ActiveRecord::Base
has_and_belongs_to_many :students
belongs_to :staff
end

class Student < ActiveRecord::Base
has_and_belongs_to_many :cse_modules
end

Why doesn’t

  # This next line should sort out the join table.
  @student_modules.each do |student, modules|
    the_student = Student.find_pnumber(student.pnumber)
    modules.each do |cse_module|
      the_cse_module = CseModule.find_aos_code(cse_module.aos_code)
      the_cse_module.students << the_student
    end
  end

leave any data in the join table cse_modules_students ?
According to my understanding of pages 240-241 of Agile Web
development it should. I don’t get any exceptions thrown. I didn’t
get errors about nonexistent tables being accessed.

    Thank you,
    Hugh