如何在 json - Rails 中包含两个嵌套的关联兄弟姐妹
How to include two nested associated siblings in json - Rails
我有这个结构
user
-> profile
-> address (table)
-> workplace (table)
我的这段代码没有按预期工作,它没有输出地址嵌套关联
def index
@users = User.all
render json: @users.as_json(include:
[:profile => {
:include => :address,:include =>:workplace
}
]
)
end
我设法让它工作在这里是答案以备将来参考
def index
@users = User.all
render json: @users.as_json(include:
[:profile => {
:include => [:address,:workplace]
}
]
)
end
我有这个结构
user
-> profile
-> address (table)
-> workplace (table)
我的这段代码没有按预期工作,它没有输出地址嵌套关联
def index
@users = User.all
render json: @users.as_json(include:
[:profile => {
:include => :address,:include =>:workplace
}
]
)
end
我设法让它工作在这里是答案以备将来参考
def index
@users = User.all
render json: @users.as_json(include:
[:profile => {
:include => [:address,:workplace]
}
]
)
end