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.

ActiveRecord json serialization should respect as_json definition of included association

#6711

When I define an as_json override in Question, and provide it with an include for the associated profile, it does not use the as_json defined in the profile model.

class Question < ActiveRecord::Base
def as_json(opts={})

super(:only => [:text],
  :include => [:profile]
)

end end

class Profile < ActiveRecord::Base
def as_json(opts={})

 super({ :only => [:display_name], :methods => [:avatar] })

end end

This will output the question as json and for the profile association, just output its id field? The only workaround I have found is to not provide an as_json on the profile and duplicate its as_json attrs everywhere I want to include it in a rendering.

Reported by Jake Dempsey · April 18th, 2011 @ 05:23 AM

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

Activity

  1. lindaouyang1
    lindaouyang1

    Chanel watches,Elegant, noble, beautiful and unique designs exclusively for women watch.

    April 18th, 2011 @ 10:35 AM