2013-12-21 32 views
0

rating.rbRuby on Rails的 - 訪問引用的連接表的對象

class Rating < ActiveRecord::Base 
    belongs_to :vote 
    belongs_to :student 
    belongs_to :course_textbook 

    validates_presence_of :vote, :student 
end 

course_textbook.rb

class CourseTextbook < ActiveRecord::Base 
    belongs_to :course 
    belongs_to :textbook 

    has_many :ratings 

    validates_presence_of :course, :textbook 
end 

是有辦法的,而不是去rating.course_textbook.textbook你去rating.textbook?我只是在模型中製作方法嗎?或者有沒有辦法讓ActiveRecord做到這一點?

感謝

回答