mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix validation based on object not _id.
From https://github.com/rails/rails/issues/6161\#issuecomment-10750118
This commit is contained in:
parent
ba2fed4161
commit
cfd324b4b6
1 changed files with 2 additions and 2 deletions
|
@ -372,12 +372,12 @@ class Person < ActiveRecord::Base
|
||||||
end
|
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
|
```ruby
|
||||||
class LineItem < ActiveRecord::Base
|
class LineItem < ActiveRecord::Base
|
||||||
belongs_to :order
|
belongs_to :order
|
||||||
validates :order_id, presence: true
|
validates :order, presence: true
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue