rails/rails — Issue #5303: Problems serializing ActiveRecord::Relation to_yaml
Author: tadast
Created: 2012-03-06 15:58:44+00:00
State: open

Hi all,

I faced a problem serializing ActiveRecord Relations in hashes:

>> {a: User.where(initials: 'TT')}.to_yaml
=> FAILS

As a workaround I convert the relation to an array

>> {a: User.where(initials: 'TT').all}.to_yaml
=> GREAT SUCCESS

Happens with syck as well

>> YAML::ENGINE.yamler = 'syck'
=> "syck"

>> {a: User.where(initials: 'TT')}.to_yaml
>> FAILS

Not sure how to handle it best? Maybe forcing #to_a in ActiveRecord::Relation#to_yaml just like #as_json does?

The full console output with stacktraces is here: https://gist.github.com/acc75942606bd8dd6063