Skip to content

pop EagerPreload or Eager support filter like where #711

@inits

Description

@inits

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: associationsthe associations feature in pops: triageSome tests need to be run to confirm the issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions