我正在尝试在我的条件中创建一个条件来检查保单是否有保险
我的桌子:
|policies|
|id| |num_policy|
1 1234
2 5678
3 9123
4 4567
|insurances|
|id| |policy_id| |net_ensurance|
1 1 1000
这就是我想要做的
If policy has an insurance do
@condition
else
nothing
end
这是我的模型:
class Policy < ActiveRecord::Base
has_many :insurances
end
class Insurance < ActiveRecord::Base
belongs_to :policy
end
这是我的控制器:
if Policy.has_insurance?
@search = Policy.find(:all,:conditions =>['deleted = 0'])
else
@search= "nothing"
end
请问有人可以帮我吗?
我将非常感谢帮助