
ActiveSupport to_json issue with STI
Reported by Greg Campbell | September 29th, 2010 @ 06:50 PM
Rails appears to have problems serializing a DataMapper STI model to JSON. The error is a ActiveSupport::JSON::Encoding::CircularReferenceError. Simple reproduction script (based on the one in ticket #1406) is attached.
Comments and changes to this ticket
-
Postmodern September 29th, 2010 @ 10:03 PM
Did you try including "DataMapper::Serializer" into the model?
-
Greg Campbell September 30th, 2010 @ 10:55 AM
I've found the problem, and am working on a patch now. The issue is that Discriminator properties have a Model class as their value, which as_json serializes as an array of all the instances of that model, which results in a circular reference. One fix (the current approach I'm taking) would be to explicitly handle Discriminator properties and call to_s on the class.
-
Dan Kubb (dkubb) September 30th, 2010 @ 01:33 PM
- State changed from unconfirmed to resolved
(from [3201e94f64c433579aa99905d0e54c6da613183f]) Serialize Discriminator properties as Strings
Previously, Discriminator properties caused problems for ActiveSupport
to_json, as their values are generally DataMapper::Model instances,
which implement as_json as an array of all the models of that type.
This caused an ActiveSupport::JSON::Encoding::CircularReferenceError.[#1421 state:resolved] http://github.com/datamapper/dm-serializer/commit/3201e94f64c433579...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Tags
Referenced by
-
1421 ActiveSupport to_json issue with STI [#1421 state:resolved] http://github.com/datamapper/dm-s...