我正在尝试将条件放入数组中。
我想
if policy.date_ini >= insurance.initial_date do
sum of all net_ensurance where date_ini >= initial_date
end
表
|policies|
|id| |date_ini| |num_policy|
1 2013-02-30 1234
|insurances|
|id| |policy_id| |initial_date| |net_ensurance|
1 1 2013-03-30 1000
2 1 2013-02-30 2000
3 1 2012-12-05 5000
我应该有
|num_policy| |sum_net_ensurance|
1234 3000
注意:我在数据库中的关系是这样的:
class Policy < ActiveRecord::Base
has_many :insurances
end
class Insurance < ActiveRecord::Base
belongs_to :policy
end