# frozen_string_literal: true require 'fancy_searchable/searchable' # == Schema Information # # Table name: reports # # id :integer not null, primary key # fingerprint :string # ip :inet not null # open :boolean default(TRUE), not null # reason :string not null # referrer :string default("") # reportable_type :string not null # state :string default("open"), not null # user_agent :string default("") # created_at :datetime not null # updated_at :datetime not null # admin_id :integer # reportable_id :integer not null # user_id :integer # # Indexes # # index_reports_on_admin_id (admin_id) # index_reports_on_created_at (created_at) # index_reports_on_open (open) # index_reports_on_user_id (user_id) # # Foreign Keys # # fk_rails_... (admin_id => users.id) ON DELETE => nullify ON UPDATE => cascade # fk_rails_... (user_id => users.id) ON DELETE => nullify ON UPDATE => cascade # class Report < ApplicationRecord include FancySearchable::Searchable include Indexable include UserAttributable include Notable resourcify belongs_to :user, inverse_of: :reports_made, optional: true belongs_to :admin, class_name: 'User', inverse_of: :managed_reports, optional: true belongs_to :reportable, polymorphic: true, optional: true validates :reason, presence: true def self.for_view includes(:admin, :reportable, user: :linked_tags) end end