collectiveidea/delayed_job — Issue #300: ActiveRecord 3.1 serialize conflict
Author: JonasNielsen
Created: 2011-10-27 10:09:47+00:00
State: open

Using delayed_job with Rails 3.1 generates a conflict with ActiveRecord 3.1's new serialize attribute method (https://github.com/rails/rails/blob/e759c8882a990606bb4aee8a643431ebe544c69f/activerecord/lib/active_record/base.rb#L560)

```ruby
class Person < ActiveRecord::Base
serialize :brain, Brain
end
```
Allows you to store Brain objects with yaml within Person records.

delayed_job I guess, is hijacking the YAML serialize/deserialize methods, so if the Brain object doesn't have an id, `Delayed::DeserializationError` will be raised.

Snippet (delayed/serialization/active_record.rb):

```ruby
if defined?(ActiveRecord)
class ActiveRecord::Base
yaml_as "tag:ruby.yaml.org,2002:ActiveRecord"

def self.yaml_new(klass, tag, val)
if ActiveRecord::VERSION::MAJOR == 3
klass.unscoped.find(val['attributes'][klass.primary_key])
else # Rails 2
klass.with_exclusive_scope { klass.find(val['attributes'][klass.primary_key]) }
end
rescue ActiveRecord::RecordNotFound
raise Delayed::DeserializationError
end

def to_yaml_properties
['@attributes']
end
end
end
```
Unfortunately, I have no clue how to solve this. Do you guys?