Forum: Ruby on Rails How to populate join tables?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
457cf540784a12ba2f30e06565a2c189?d=identicon&s=25 hgs (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
This topic is locked and can not be replied to.