提交 cfd324b4 编写于 作者: S Steve Klabnik

Fix validation based on object not _id.

From https://github.com/rails/rails/issues/6161\#issuecomment-10750118
上级 ba2fed41
......@@ -372,12 +372,12 @@ class Person < ActiveRecord::Base
end
```
If you want to be sure that an association is present, you'll need to test whether the foreign key used to map the association is present, and not the associated object itself.
If you want to be sure that an association is present, you'll need to test the associated object itself, and not whether the foreign key used to map the association is present:
```ruby
class LineItem < ActiveRecord::Base
belongs_to :order
validates :order_id, presence: true
validates :order, presence: true
end
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册