Skip to content

Instantly share code, notes, and snippets.

@ascruggs
Created December 10, 2015 17:12
Show Gist options
  • Save ascruggs/dd7e794e509098b3f7fb to your computer and use it in GitHub Desktop.
Save ascruggs/dd7e794e509098b3f7fb to your computer and use it in GitHub Desktop.
class Teacher < ActiveRecord::Base
has_many :courses
has_many :lightbulbs, :through => "courses"
end
class Course < ActiveRecord::Base
has_many :lightbulbs
end
class Lightbulb < ActiveRecord::Base
end
teacher = Teacher.find 1
teacher.courses
#I thought the relationships were more complicated than this, but it maps to the example you send and hopefully illustrates the point
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment