Hi,
These are my models:
class Advisor < ActiveRecord::Base
set_table_name “advisors”
set_primary_key “id”
has_many :advisee, :class_name=>“Student”, :foreign_key=>
“advisor_id”
has_many :second_advisee, :class_name=>“Student”, :foreign_key=>
“sub_advisor”
end
class Student < ActiveRecord::Base
set_table_name “students”
set_primary_key “id”
belongs_to :advisor, :class_name=>“Advisor”, :foreign_key =>
“advisor_id”
belongs_to :second_advisor, :class_name=>“Advisor”, :foreign_key =>
“sub_advisor”
has_and_belongs_to_many :courses, :class_name=>“Course”
end
class Course < ActiveRecord::Base
set_table_name “courses”
set_primary_key “id”
has_and_belongs_to_many :students, :class_name=>“Student”
end
In my script/console>
How can i find the first student?
How can i find the first student and all her/his courses?
How can i find the first advisor ?
How can i find the first advisor students?
Thanks…remco