Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

to_json on ActiveRecord::Relation throws CircularReference Exception

#4573

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.

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

State: duplicate
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Neeraj Singh
    Neeraj Singh

    This is a duplicate of #4547 ActiveSupport #to_json doesn't work with DM .

    @blackgold Could you please provide more information about your model so that I could look into this issue. Please provide extra info on #4547 ActiveSupport #to_json doesn't work with DM ticket.

    Thanks

    May 11th, 2010 @ 06:13 PM

  2. Ryan Bigg