2012-08-31 65 views
0

enrollment.rb計數父梁2

attr_accessible :semester_id 
has_many :studentpayments 
has_many :student_deductions 

studentpayment.rb

belongs_to :enrollment 

student_deduction.rb

belongs_to :enrollment 

我如何獲得的唯一的登記基礎上,semester_id如果enrollmentstudentpayment或有student_deduction

回答

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?