qor-example icon indicating copy to clipboard operation
qor-example copied to clipboard

bottom_sheet not working with 1-n relationship

Open Kiennh opened this issue 7 years ago • 1 comments

Hi,

My sample program:

package main

import (
        "fmt"
        "net/http"

        "github.com/jinzhu/gorm"
        _ "github.com/jinzhu/gorm/dialects/mysql"
        _ "github.com/mattn/go-sqlite3"

        "github.com/qor/admin"
        "github.com/qor/qor"
)

// Create a GORM-backend model
type User struct {
        gorm.Model
        Name     string
        Products []Product
}

// Create another GORM-backend model
type Product struct {
        gorm.Model
        Name        string
        Description string
        UserID      uint
}

func main() {
        DB, err := gorm.Open("mysql", "***")
        if err != nil {
                fmt.Println(err)
                return
        }
        defer DB.Close()
        DB.AutoMigrate(&User{}, &Product{})

        // Initalize
        Admin := admin.New(&qor.Config{DB: DB})

        // Create resources from GORM-backend model
        user := Admin.AddResource(&User{})
        product := Admin.AddResource(&Product{})

        user.Meta(&admin.Meta{Name: "Products",
                Config: &admin.SelectManyConfig{SelectMode: "bottom_sheet", RemoteDataResource: product},
        })
        // Register route

        mux := http.NewServeMux()
        // amount to /admin, so visit `/admin` to view the admin interface
        Admin.MountTo("/admin", mux)
        fmt.Println("started")
        http.ListenAndServe(":9000", mux)
}

When i add products to an user then click save, the reference are not updated so this user do not have any products linked with.

Kiennh avatar Nov 13 '17 09:11 Kiennh

It should be a bug, but there is a temporary solution to make it works by setting the meta's type to select_many (which should not be required), e.g:

 user.Meta(&admin.Meta{Name: "Products", Type: "select_many", 
                Config: &admin.SelectManyConfig{SelectMode: "bottom_sheet", RemoteDataResource: product},
 })

Thank you for your report.

jinzhu avatar Nov 13 '17 09:11 jinzhu