With the following schema, is it possible to filter out version
in %Post{}
and password
from %User{}
with a preload query and select?
I’m able to filter out password
from %User{}
, but cannot remove version
in %Post{}
.
# Post
schema "posts" do
field :id
field :title
field :version
has_many(:user_ids, MyApp.UserPost, on_replace: :delete)
has_many(:users, through: [:user_ids, :user], preload_order: [asc: :username])
end
# User
schema "users" do
field :id
field :username
field :password
end
I would like to output a map like this.
[%{
id: 80,
title: "title",
user_ids: [ %{ id: 1 }, %{ id: 2 }, %{ id: 3 } ]
}]
This gives me ** (Tds.Error) Line 1 (Error 207): Invalid column name 'user_ids'.
user_ids_query = from u in UserPost, select: %{id: u.user_id}
query =
from p in Post,
where: p.id == 80,
preload: [user_ids: ^user_ids_query],
select: map(p, [:id, :title, :user_ids]) # error here
Without the select in query
, it gives me all the fields of %Post{}
, but user_ids
is correct.
[%Post{
...
id: 80,
title: "title",
version: 3,
user_ids: [ %{ id: 1 }, %{ id: 2 }, %{ id: 3 } ]
}]