Hello, I have a struct that was made with preload, this output cannot be converted to json encode.
it should be noted, I can’t use @derive in my schema files, but I use it in my query file, but the task was broken , because I have multi struct in a list.
now how can I convert it to json, I’m using Jason lib,
my preload:
def show_support_with_code(code, user_id) do
query = from u in SupportSchema,
where: u.code == ^code,
join: a in assoc(u, :users),
# where: a.id == ^user_id,
left_join: b in assoc(u, :blog_posts),
left_join: c in assoc(u, :support_replies),
left_join: d in assoc(c, :users),
order_by: [desc: c.inserted_at],
preload: [users: a, blog_posts: b, support_replies: {c, users: d}]
case Repo.one(query) do
nil -> {:error, :show_support_with_code}
info -> {:ok, :show_support_with_code, info}
end
end
output preload:
%BankError.ClientApi.Support.SupportSchema{
__meta__: #Ecto.Schema.Metadata<:loaded, "supports">,
blog_posts: nil,
code: "test47",
description: "بررسی بهینه سازی در اگهی",
id: "cd33f63f-44c5-46a7-848c-8926be21dd82",
inserted_at: ~N[2019-08-25 17:43:49],
post_id: nil,
status: 3,
support_replies: [
%BankError.Support.SupportReplySchema{
__meta__: #Ecto.Schema.Metadata<:loaded, "support_replies">,
description: "برای تست اینجاییم",
id: "e67dae2f-237c-439f-bee7-846f8f575cc9",
inserted_at: ~N[2019-08-29 17:24:25],
status: true,
support_id: "cd33f63f-44c5-46a7-848c-8926be21dd82",
supports: #Ecto.Association.NotLoaded<association :supports is not loaded>,
updated_at: ~N[2019-08-29 17:24:26],
user_id: "40c06a6b-15a0-4888-999b-132fbd326455",
users: %BankError.Users.UserSchema{
__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
id: "40c06a6b-15a0-4888-999b-132fbd326455",
inserted_at: ~N[2019-05-26 08:12:14],
last_name: "soam",
mobile: "09213780329",
name: "shiam",
password: nil,
password_hash: "$2b$12$N2c6fKCVez7ZB/5k7coXkuwNaVGESQboFNba8cmRcRqoaKufs4PAC",
role: 1,
status: 1,
support_replies: #Ecto.Association.NotLoaded<association :support_replies is not loaded>,
supports: #Ecto.Association.NotLoaded<association :supports is not loaded>,
transactions: #Ecto.Association.NotLoaded<association :transactions is not loaded>,
updated_at: ~N[2019-05-26 08:12:14]
}
}
],
title: "ساختمان سازی یک تست دوم",
type: "other",
updated_at: ~N[2019-08-26 06:29:23],
user_id: "d0c1c8c5-6747-47c7-ba21-89a15017be3c",
users: %BankError.Users.UserSchema{
__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
id: "d0c1c8c5-6747-47c7-ba21-89a15017be3c",
inserted_at: ~N[2019-04-16 08:20:10],
last_name: "tavakkoli",
mobile: "09368094936",
name: "shahryar",
password: nil,
password_hash: "$2b$12$k/Ql7o9VyUbeeHi3Dr1BuOub2Wdg6NZ0I8bIfM8SmaqNop8o60H.G",
role: 3,
status: 2,
support_replies: #Ecto.Association.NotLoaded<association :support_replies is not loaded>,
supports: #Ecto.Association.NotLoaded<association :supports is not loaded>,
transactions: #Ecto.Association.NotLoaded<association :transactions is not loaded>,
updated_at: ~N[2019-08-26 05:38:18]
}
}