Why do i get a circular reference exception when calling to_json on an ActiveRecord::Relation

Posted by midas06 on Stack Overflow See other posts from Stack Overflow or by midas06
Published on 2010-05-10T22:45:25Z Indexed on 2010/05/23 0:50 UTC
Read the original article Hit count: 280

In Rails 3 (beta 3 on 1.8.7), when calling to_json on a relation i get a circular reference exception. Converting that relation to an array first, and THEN calling to_json works.

Code That fails:

Model.where().to_json (Where model is any model in your Rails 3 app)

Code that works:

Model.where().to_a.to_json

This can be reproed on the console.

Has anyone else run in to this? Is this expected?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails3