在嵌套属性rails 2上计算Parent

时间:2012-08-31 08:57:36

标签: ruby-on-rails

我的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以及enrollmentstudentpaymentstudent_deduction

,我如何获得唯一的注册记录?

1 个答案:

答案 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?