我有两个模型,教师和教师领袖:
# id :integer
# last_name :string(255)
class Teacher < ActiveRecord::Base
has_one :teacher_leader
end
# teacher_id :integer
class TeacherLeader < ActiveRecord::Base
belongs_to :teacher
end
我想让所有老师领导的老师通过last_name
对他们进行排序。我怎么能这样做?
答案 0 :(得分:1)
Teacher.joins(:teacher_leader).uniq.order(:last_name)