This project is archived and is in readonly mode.

#4573 ✓duplicate
blackgold9

to_json on ActiveRecord::Relation throws CircularReference Exception

Reported by blackgold9 | May 10th, 2010 @ 11:42 PM

In my controller I'm querying a table using an ActiveRecord model and trying to return json.
When I attempt to call to_json on an ActiveRecord::Relation, I get a circular reference exception. When I call to_a on the relation and THEN call to_json, it works.

Code that fails:

Model.where().to_json

Code that works

Model.where().to_a.to_json

This is reproducable on the rails console.

Is this expected? It seems wrong/non-discoverable if it is.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages