class Tiding < ApplicationRecord belongs_to :user belongs_to :trigger_user, class_name: 'User', optional: true belongs_to :container, polymorphic: true, optional: true belongs_to :parent_container, polymorphic: true, optional: true belongs_to :belong_container, polymorphic: true, optional: true has_many :attachments, as: :container def identifier value = nil if Object.const_defined?(container_type) value = container.try(:identifier) end if value.blank? && belong_container_type && Object.const_defined?(belong_container_type) value = belong_container.try(:identifier) end value end end