新手问题 Rails 中多对多关系如何做校验

ytwman · 2013年09月11日 · 最后由 cisolarix 回复于 2014年04月09日 · 1960 次阅读

我现在有两个 Model 分别是 House 和 Company 对应的是多对多关系,并且有张中间表 house_companies。我想在插入 House 或者 Company 的时候验证下另一边的对象是否存在,该怎么做呢?有人建议我在中间表中做,但是感觉不是这样的。

foreign_key

#1 楼 @nouse 不太明白,能介绍下得么?

#3 楼 @nouse google 了下,去他妈的文档??

#4 楼 @ytwman

validate
If you set the :validate option to true, then associated objects will be validated whenever you save this object. By default, this is false: associated objects will not be validated when this object is saved.
需要 登录 后方可回复, 如果你还没有账号请 注册新账号