require 'subj_models/concerns/comprising_external_id' module SubjModels module ContentBlockModule def self.included(including_class) including_class.class_eval do include SubjModels::ComprisingExternalId belongs_to :document_file has_one :brand end end def to_s brands = Brand.where('content_block1_id=? OR (content_block2_id=? OR content_block3_id=?)', id, id, id) addition_text = brands.any? ? "#{brands.first.try(:name)}" : 'Без бренда' "#{title} - " + addition_text end end end