require 'active_record' class PermissionPolicy < ActiveRecord::Base belongs_to :resource, polymorphic: true validates :resource_id, uniqueness: { scope: [:resource_id, :resource_type] } end