Skip to content

Load multiple models with true eager loading #1227

Answered by stephenafamo
alex-ntousias asked this question in Q&A
Discussion options

You must be logged in to vote

You have to prefix the alias names correctly for bind to work.

type IntermediateModel struct {
  TableA TableA `boil:"tablea,bind"` // Note ",bind"
  TableB TableB `boil:"tableb,bind"`
}

func retrieveModels(id string) IntermediateModel {
  var response IntermediateModel
  err := queries.Raw(`
    SELECT 
        tablea.id AS "tablea.id",
        tablea.value AS "tablea.value",
        tableb.id AS "tablea.tableb_id",
        tableb.id AS "tableb.id",
        tableb.value AS "tableb.value"
    FROM tablea
    INNER JOIN tableb ON tableb.id = tablea.tableb_id
    WHERE tablea.id=$1`, id).Bind(ctx, exec, &response)
  
  return response
}

I understand this is not very user friendly, but this…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by stephenafamo
Comment options

You must be logged in to vote
3 replies
@stephenafamo
Comment options

@alex-ntousias
Comment options

@stephenafamo
Comment options

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