我有:
Aulas
has_many :grades
has_many :students, :through => :grades
Students
has_many :grades
has_many :aulas, :through => :grades
Grades
belongs_to :aula
belongs_to :student
我想grades.name
从 Aula 和 Aula 内的特定学生之间的连接中显示出来。这不起作用,但你会明白我想要什么:
<% aula.students.each do |student| %>
<%= link_to student.name, student %>-<%= student.grade.name %>
<% end %>
好的,我在 Aula (id:68) 里面,如果我做students.grades,我会从所有 Aula
[#<Grade id: 51, name: AA1, student_id: 22, aula_id: 68 >,#<Grade id: 52, name: AA2, student_id: 22, aula_id: 69 >,#<Grade id: 53, name: AA3, student_id: 22, aula_id: 70 >]
我如何仅获得与此 Aula (aula_id:68) 相关的年级名称?