ActiveRecorder json serialization should not use keys defined in :methods for included associations #1030

Closed
lighthouse-import opened this Issue May 16, 2011 · 0 comments

1 participant

@lighthouse-import

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6710
Created by Jake Dempsey - 2011-04-18 04:14:19 UTC

I am currently using as_json with something similar to:

def as_json(opts={})
super(:only => [:foo],
:methods => [:some_method?],
:include => {
:assoc => { :only => [:bar] }
}
)
end

When I render my object to json, I notice that some_method? is being rendered in my json hash for the assoc object. The only workaround I have been able to come up with is to pass an empty [] to the :assoc like:

def as_json(opts={})
super(:only => [:foo],
:methods => [:some_method?],
:include => {
:assoc => { :only => [:bar], :methods => [] }
}
)
end

Is that the intended behavior? It does not seem intuitive that the methods declared at the root for the as_json would get inherited by an included association if no methods are defined for the included association. Bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment