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做到這一點?
感謝
這很完美,謝謝!我知道軌道會有一些東西。謝謝一堆。當我被允許時,我一定會接受這個答案。 – adamk33n3r