class ActiveRecord::Base

def self.yaml_new(klass, tag, val)

def self.yaml_new(klass, tag, val)
  Apartment::Database.process(val['database']) do
    klass.find(val['attributes']['id'])
  end
rescue ActiveRecord::RecordNotFound => e
  raise Delayed::DeserializationError,  e.message
end

def encode_with_with_database(coder)

@override to include database attribute
Rails > 3.0 now uses encode_with to determine what to encode with yaml
def encode_with_with_database(coder)
  coder['database'] = @database if @database.present?
  encode_with_without_database(coder)
end

def to_yaml_properties

Remain backwards compatible with old yaml serialization
def to_yaml_properties
  ['@attributes', '@database']    # add in database attribute for serialization
end