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

ytwman · September 11, 2013 · Last by cisolarix replied at April 09, 2014 · 1956 hits

我现在有两个 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.
You need to Sign in before reply, if you don't have an account, please Sign up first.