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
|
@ -3,14 +3,14 @@
|
|||
class Favourite < ApplicationRecord
|
||||
include Paginable
|
||||
|
||||
belongs_to :account, inverse_of: :favourites
|
||||
belongs_to :status, inverse_of: :favourites, counter_cache: true
|
||||
belongs_to :account, inverse_of: :favourites, required: true
|
||||
belongs_to :status, inverse_of: :favourites, counter_cache: true, required: true
|
||||
|
||||
has_one :notification, as: :activity, dependent: :destroy
|
||||
|
||||
validates :status_id, uniqueness: { scope: :account_id }
|
||||
|
||||
before_validation do
|
||||
self.status = status.reblog if status.reblog?
|
||||
self.status = status.reblog if status&.reblog?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue