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.

AR::Relation can't be encoded to JSON

#5073

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.

Reported by Mislav · July 8th, 2010 @ 09:26 PM

State: resolved
Milestone: 3.x
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Rohit Arondekar
    Rohit Arondekar
    • 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

    July 9th, 2010 @ 02:35 AM

  2. Mislav
    Mislav

    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.

    July 10th, 2010 @ 05:11 PM

  3. Neeraj Singh
    Neeraj Singh
    • Milestone set to 3.x
    • Assigned user set to José Valim

    +1 works great

    July 10th, 2010 @ 05:51 PM

  4. Repository
    Repository
    • State changed from open to resolved

    (from [571cb1ddc6692ed96e04a14e670beb01ba8c93ca]) enable AS::JSON.encode to encode AR::Relation by providing as_json method

    [#5073 AR::Relation can't be encoded to JSON state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/571cb1ddc6692ed96e04a14e670beb...

    July 13th, 2010 @ 07:37 AM