gobuffalo / pop

A Tasty Treat For All Your Database Needs
MIT License
1.43k stars 241 forks source link

pop EagerPreload or Eager support filter like where #711

Open inits opened 2 years ago

inits commented 2 years ago

pop EagerPreload or Eager support filter like where ?

like this

func (v TreesResource) Show(c buffalo.Context) error {
    // Get the DB connection from the context
    tx, ok := c.Value("tx").(*pop.Connection)
    if !ok {
        return fmt.Errorf("no transaction found")
    }

    // Allocate an empty Tree
    tree := &models.Tree{}

    // To find the Tree the parameter tree_id is used.
    if err := tx.EagerPreload("id in (?)", "1","2").Find(tree, c.Param("tree_id")); err != nil {
        return c.Error(http.StatusNotFound, err)
    }

    return responder.Wants("html", func(c buffalo.Context) error {
        c.Set("tree", tree)

        return c.Render(http.StatusOK, r.HTML("trees/show.plush.html"))
    }).Wants("json", func(c buffalo.Context) error {
        return c.Render(200, r.JSON(tree))
    }).Wants("xml", func(c buffalo.Context) error {
        return c.Render(200, r.XML(tree))
    }).Respond(c)
}
inits commented 2 years ago

like this query:

 tx.EagerPreload("id in (?)", "1","2").Find(tree, c.Param("tree_id"))