Required foreign keys (#2003)
* Add `required: true` option to foreign column * Fixes NoMethodError ``` > Favourite.new.valid? NoMethodError: undefined method `reblog?' for nil:NilClass ```
This commit is contained in:
parent
f8546ad5a2
commit
630de52fdd
5 changed files with 8 additions and 11 deletions
|
@ -10,7 +10,7 @@ class Status < ApplicationRecord
|
|||
|
||||
belongs_to :application, class_name: 'Doorkeeper::Application'
|
||||
|
||||
belongs_to :account, inverse_of: :statuses, counter_cache: true
|
||||
belongs_to :account, inverse_of: :statuses, counter_cache: true, required: true
|
||||
belongs_to :in_reply_to_account, foreign_key: 'in_reply_to_account_id', class_name: 'Account'
|
||||
|
||||
belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies
|
||||
|
@ -26,7 +26,6 @@ class Status < ApplicationRecord
|
|||
has_one :notification, as: :activity, dependent: :destroy
|
||||
has_one :preview_card, dependent: :destroy
|
||||
|
||||
validates :account, presence: true
|
||||
validates :uri, uniqueness: true, unless: 'local?'
|
||||
validates :text, presence: true, unless: 'reblog?'
|
||||
validates_with StatusLengthValidator
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue