我的enrollment.rb
attr_accessible :semester_id
has_many :studentpayments
has_many :student_deductions
我的studentpayment.rb
belongs_to :enrollment
我的student_deduction.rb
belongs_to :enrollment
如何semester_id
以及enrollment
有studentpayment
或student_deduction
答案 0 :(得分:1)
@enrollment = Enrollment.find_by_semester_id(id) # find by semester_id
@enrollment.studentpayments.any? # if @enrollment has any student payments
@enrollment.student_deductions.any?