hummingbird-me/kitsu-server

View on GitHub
app/models/casting.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
class Casting < ApplicationRecord
  belongs_to :media, polymorphic: true, touch: true
  belongs_to :character, touch: true, optional: true
  belongs_to :person, touch: true, optional: true

  validates :media, presence: true, polymorphism: { type: Media }
  # Require either character or person
  validates :character, presence: true, unless: :person
  validates :person, presence: true, unless: :character
end