I'm a bit confused and need some help.
I have Universities and each University has a City (one to many).
I need to take 2 Universities. I do:
universities = University
|> limit(2)
|> Repo.all
Since, I don't need Poison to return metadata and need only some fields, I do:
universities = University
|> limit(2)
|> select([u], %{ title: u.fullTitle
})
|> Repo.all
So, on client I receive this:
[
{
title: "title one"
},
{
title: "title two"
}
]
Now, I need to preload city
If I take the whole data and preload city - it works:
universities = University
|> preload(:city)
|> limit(2)
|> select([u], u)
|> Repo.all
But, I don't know, how to exclude metadata and take only needed columns here. I want to receive on client this:
[
{
title: "title one",
city: {
title: "city one"
}
},
{
title: "title two"
city: {
title: "city two"
}
}
]
I keep rereading the docs and trying various syntax combinations, but I can't handle it.
Can you help me, please?