Skip to content

Use Select inside a With Function #3070

Answered by a8m
niwla23 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @niwla23 👋🏻
You can pass functions to configure the sub-query as follows:

pets, err := client.Pet.
    Query().
    Select(pet.FieldName).
    WithOwner(func (q *ent.UserQuery) {
        q.Select(user.FieldName)
    }).
    All(ctx)

Note, there is also an example for it in our doc. Please, see: https://entgo.io/docs/crud#field-selection

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@niwla23
Comment options

Answer selected by niwla23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants