I am trying to transfer a nested JSON from Rails to JavaScript.
So far I successfully transfer following JSON:
[
"name" : "task-1",
"relationships" : [
{"follower": {"name" : "task-2"}},
{"follower": {"name" : "task-3"}}
]
I would like to format this JSON to look like this:
[
"name" : "task-1",
"relationships" : [
{"name" : "task-2"},
{"name" : "task-3"}
]
Here is how I generate JSON:
@tasks.to_json(
:include => { :relationships => {
:include => :follower,
:only => :follower
} })
Is there some kind of option that I can specify in my to_json function to get rid off “follower” key name?
I ended up using different query to solve the problem:
Where
followed_tasksis defined in theTaskmodel:This gives me nicely formatted JSON: