Monday, 9 September 2013

as_json not including association

as_json not including association

I am trying to override the as_json method in my Edge class so I can
include the x and y coordinates of it's from and to Vertex.
The assosiations are like this:
Edge belongs_to :from and :to Vertex.
Vertex has_many :edges, where :x and :y are fields.
I have tried several syntactic variation, like the one below, but can't
get it to work. Thanks for any help!
def as_json(options={})
super only: [:name, :value, :color], include: [
{ from: { only: [:x, :y] } },
{ to: { only: [:x, :y] } }
end

No comments:

Post a Comment