我是新手,很困惑,我有点困惑。我有三张桌子
______________ ____________________ _____________________
| employees | | abilitys | | services |
|--------------| |--------------------| |---------------------|
|id | integer|__ |id | integer| __|id | integer|
|name | string | |_->|employee_id| integer| | |description | string |
|______________| |service_id | integer| <-| |_____________________|
|______________| |____________________|
我想知道是否只有在employees表中确实存在employee的情况下才能接受能力的插入。service_id也是如此。
我必须在hability.rb文件中进行验证还是在视图中进行验证?
谢谢。
是的,您可以在模型中执行此操作(验证应在模型中定义):
class Ability < ActiveRecord::Base
belongs_to :employee
belongs_to :service
validates :employee, :presence => true, :associated => true
validates :service, :presence => true, :associated => true
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句