class Library::Contributor < ApplicationRecord
  belongs_to :school

  has_many :bib_contributors, foreign_key: :contributor_id
  has_many :bibs, through: :bib_contributors

  validates :name, uniqueness: { scope: :school_id, case_sensitive: true }, presence: true,
    length: { maximum: 128 }

  scope :search, ->(term) { where('name LIKE :term', term: "#{term}%") if term }
end
