我有一个基本上是 API 的 Phoenix 应用程序。我有以下看法:
defmodule TattooBackend.Web.API.V1.AccountView do
use TattooBackend.Web, :view
alias TattooBackend.Repo
def render("my_account.json", %{account: account}) do
account = account |> Repo.preload(:studio)
studio = account.studio
%{
id: account.id,
email: account.email,
studio: %{
id: account.studio.id,
name: account.studio.name
}
}
end
end
当我在 Postman 中触发此端点时,它会以以下格式返回响应:
{
"studio": {
"name": "asdasdsadsa123123",
"id": 4
},
"id": 1,
"email": "chujbasd@o2.pl"
}
为什么“id”和“email”在最后?他们应该是第一...