This project is archived and is in readonly mode.
AR::Relation can't be encoded to JSON
Reported by Mislav | July 8th, 2010 @ 09:26 PM | in 3.x
Although AR::Relation provides to_json
, it still
can't be encoded with ActiveSupport::JSON.encode
because the latter detects a circular reference and errors out. So,
this is not possible:
# controller action
render :json => relation
I fixed it by providing as_json
method in
AR::Relation.
Comments and changes to this ticket
-
Rohit Arondekar July 9th, 2010 @ 02:35 AM
- State changed from new to open
- Importance changed from to Low
Can you please make a patch according to this http://rails.lighthouseapp.com/projects/8994/sending-patches
-
Mislav July 10th, 2010 @ 05:11 PM
What's wrong with pushing changes to my remote? With hub, the above link can be cherry-picked by just doing this:
$ git cherry-pick http://github.com/mislav/rails/commit/59a4fe0a09
This is much faster and easier than applying mailbox-formatted patch files.
-
Neeraj Singh July 10th, 2010 @ 05:51 PM
- Milestone set to 3.x
- Assigned user set to José Valim
+1 works great
-
Repository July 13th, 2010 @ 07:37 AM
- State changed from open to resolved
(from [571cb1ddc6692ed96e04a14e670beb01ba8c93ca]) enable AS::JSON.encode to encode AR::Relation by providing
as_json
method[#5073 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/571cb1ddc6692ed96e04a14e670beb...
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
Referenced by
- 5073 AR::Relation can't be encoded to JSON [#5073 state:resolved]