Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pq: column "_id" does not exist #302

Closed
cippaciong opened this issue Nov 13, 2018 · 4 comments
Closed

pq: column "_id" does not exist #302

cippaciong opened this issue Nov 13, 2018 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@cippaciong
Copy link

cippaciong commented Nov 13, 2018

Description

I have update Pop to v4.9.0 and I'm trying out the newly introduced support for pointers that would be helpful to integrate more easily with google/jsonapi.
I have this code that is failing with a Postgres error though

parent := &models.Parent{}
// Load the parent and all the students
if err := tx.Eager("Students").Find(parent, c.Param("parent_id")); err != nil {
// FAIL: pq: column "_id" does not exist

The model of Parent looks like this:

type Parent struct {
    ID        uuid.UUID  `json:"id" db:"id" jsonapi:"primary,parents"`
    CreatedAt time.Time  `json:"created_at" db:"created_at" jsonapi:"attr,created_at,iso8601"`
    UpdatedAt time.Time  `json:"updated_at" db:"updated_at" jsonapi:"attr,updated_at,iso8601"`
    Email     string     `json:"email" db:"email" jsonapi:"attr,email"`
    Password  string     `json:"passowrd" db:"-" jsonapi:"attr,password,omitempty"`
    Name      string     `json:"name" db:"name" jsonapi:"attr,name"`
    Surname   string     `json:"surname" db:"surname" jsonapi:"attr,surname"`
    UserID    uuid.UUID  `db:"user_id"`
    User      *User      `db:"-" jsonapi:"relation,user,omitempty"`
    Students  []*Student `many_to_many:"parents_students" jsonapi:"relation,students"`
}

This is the complete stack trace:

github.com/gobuffalo/pop.genericSelectMany
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/dialect.go:140
github.com/gobuffalo/pop.(*postgresql).SelectMany
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/dialect_postgresql.go:96
github.com/gobuffalo/pop.(*Query).All.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:144
github.com/gobuffalo/pop.(*Connection).timeFunc
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:206
github.com/gobuffalo/pop.(*Query).All
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:142
github.com/gobuffalo/pop.(*Query).eagerAssociations
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:253
github.com/gobuffalo/pop.(*Query).First
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:88
github.com/gobuffalo/pop.(*Query).Find
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:53
github.com/gobuffalo/pop.(*Connection).Find
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:25
github.com/middleware2018-PSS/back2_school/actions.StudentsResource.List
	/home/cippaciong/.go/src/github.com/middleware2018-PSS/back2_school/actions/students.go:51
github.com/middleware2018-PSS/back2_school/actions.(*StudentsResource).List
	<autogenerated>:1
github.com/gobuffalo/buffalo.Resource.List-fm
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/route_mappings.go:150
github.com/middleware2018-PSS/back2_school/middleware/authorization.New.func1.1
	/home/cippaciong/.go/src/github.com/middleware2018-PSS/back2_school/middleware/authorization/authorization.go:52
github.com/gobuffalo/mw-tokenauth.New.func1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-tokenauth@v0.0.0-20181001105134-8545f626c189/tokenauth.go:115
github.com/gobuffalo/buffalo-pop/pop/popmw.Transaction.func2.1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo-pop@v1.1.13/pop/popmw/tx.go:52
github.com/gobuffalo/pop.(*Connection).Transaction.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:123
github.com/gobuffalo/pop.(*postgresql).Lock
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/dialect_postgresql.go:183
github.com/gobuffalo/pop.(*Connection).Transaction
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:117
github.com/gobuffalo/buffalo-pop/pop/popmw.Transaction.func2.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo-pop@v1.1.13/pop/popmw/tx.go:39
github.com/gobuffalo/mw-paramlogger.parameterLogger.Middleware.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-paramlogger@v0.0.0-20181005191442-d6ee392ec72e/param_logger.go:63
github.com/gobuffalo/mw-contenttype.Set.func1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-contenttype@v0.0.0-20180802152300-74f5a47f4d56/content_type.go:11
github.com/gobuffalo/buffalo.sessionSaver.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/session.go:70
github.com/gobuffalo/buffalo.RequestLoggerFunc.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/request_logger.go:54
github.com/gobuffalo/buffalo.(*App).PanicHandler.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:82
github.com/gobuffalo/buffalo.(*App).defaultErrorMiddleware.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:88
github.com/gobuffalo/buffalo.RouteInfo.ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/route_info.go:108
github.com/gobuffalo/buffalo.(*RouteInfo).ServeHTTP
	<autogenerated>:1
github.com/gorilla/mux.(*Router).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gorilla/mux@v1.6.2/mux.go:162
github.com/markbates/refresh/refresh/web.ErrorChecker.func1
	/home/cippaciong/.go/pkg/mod/github.com/markbates/refresh@v1.4.11/refresh/web/web.go:23
net/http.HandlerFunc.ServeHTTP
	/usr/lib/go/src/net/http/server.go:1964
github.com/gobuffalo/buffalo.(*App).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/server.go:126
net/http.serverHandler.ServeHTTP
	/usr/lib/go/src/net/http/server.go:2741
github.com/gobuffalo/pop.(*Connection).timeFunc
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:209
github.com/gobuffalo/pop.(*Query).All
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:142
github.com/gobuffalo/pop.(*Query).eagerAssociations
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:253
github.com/gobuffalo/pop.(*Query).First
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:88
github.com/gobuffalo/pop.(*Query).Find
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:53
github.com/gobuffalo/pop.(*Connection).Find
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/finders.go:25
github.com/middleware2018-PSS/back2_school/actions.StudentsResource.List
	/home/cippaciong/.go/src/github.com/middleware2018-PSS/back2_school/actions/students.go:51
github.com/middleware2018-PSS/back2_school/actions.(*StudentsResource).List
	<autogenerated>:1
github.com/gobuffalo/buffalo.Resource.List-fm
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/route_mappings.go:150
github.com/middleware2018-PSS/back2_school/middleware/authorization.New.func1.1
	/home/cippaciong/.go/src/github.com/middleware2018-PSS/back2_school/middleware/authorization/authorization.go:52
github.com/gobuffalo/mw-tokenauth.New.func1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-tokenauth@v0.0.0-20181001105134-8545f626c189/tokenauth.go:115
github.com/gobuffalo/buffalo-pop/pop/popmw.Transaction.func2.1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo-pop@v1.1.13/pop/popmw/tx.go:52
github.com/gobuffalo/pop.(*Connection).Transaction.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:123
github.com/gobuffalo/pop.(*postgresql).Lock
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/dialect_postgresql.go:183
github.com/gobuffalo/pop.(*Connection).Transaction
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:117
github.com/gobuffalo/buffalo-pop/pop/popmw.Transaction.func2.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo-pop@v1.1.13/pop/popmw/tx.go:39
github.com/gobuffalo/mw-paramlogger.parameterLogger.Middleware.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-paramlogger@v0.0.0-20181005191442-d6ee392ec72e/param_logger.go:63
github.com/gobuffalo/mw-contenttype.Set.func1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-contenttype@v0.0.0-20180802152300-74f5a47f4d56/content_type.go:11
github.com/gobuffalo/buffalo.sessionSaver.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/session.go:70
github.com/gobuffalo/buffalo.RequestLoggerFunc.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/request_logger.go:54
github.com/gobuffalo/buffalo.(*App).PanicHandler.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:82
github.com/gobuffalo/buffalo.(*App).defaultErrorMiddleware.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:88
github.com/gobuffalo/buffalo.RouteInfo.ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/route_info.go:108
github.com/gobuffalo/buffalo.(*RouteInfo).ServeHTTP
	<autogenerated>:1
github.com/gorilla/mux.(*Router).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gorilla/mux@v1.6.2/mux.go:162
github.com/markbates/refresh/refresh/web.ErrorChecker.func1
	/home/cippaciong/.go/pkg/mod/github.com/markbates/refresh@v1.4.11/refresh/web/web.go:23
net/http.HandlerFunc.ServeHTTP
	/usr/lib/go/src/net/http/server.go:1964
github.com/gobuffalo/buffalo.(*App).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/server.go:126
net/http.serverHandler.ServeHTTP
	/usr/lib/go/src/net/http/server.go:2741
net/http.(*conn).serve
	/usr/lib/go/src/net/http/server.go:1847
runtime.goexit
	/usr/lib/go/src/runtime/asm_amd64.s:1333
github.com/middleware2018-PSS/back2_school/actions.apiError
	/home/cippaciong/.go/src/github.com/middleware2018-PSS/back2_school/actions/errors.go:25
github.com/middleware2018-PSS/back2_school/actions.StudentsResource.List
	/home/cippaciong/.go/src/github.com/middleware2018-PSS/back2_school/actions/students.go:55
github.com/middleware2018-PSS/back2_school/actions.(*StudentsResource).List
	<autogenerated>:1
github.com/gobuffalo/buffalo.Resource.List-fm
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/route_mappings.go:150
github.com/middleware2018-PSS/back2_school/middleware/authorization.New.func1.1
	/home/cippaciong/.go/src/github.com/middleware2018-PSS/back2_school/middleware/authorization/authorization.go:52
github.com/gobuffalo/mw-tokenauth.New.func1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-tokenauth@v0.0.0-20181001105134-8545f626c189/tokenauth.go:115
github.com/gobuffalo/buffalo-pop/pop/popmw.Transaction.func2.1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo-pop@v1.1.13/pop/popmw/tx.go:52
github.com/gobuffalo/pop.(*Connection).Transaction.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:123
github.com/gobuffalo/pop.(*postgresql).Lock
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/dialect_postgresql.go:183
github.com/gobuffalo/pop.(*Connection).Transaction
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:117
github.com/gobuffalo/buffalo-pop/pop/popmw.Transaction.func2.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo-pop@v1.1.13/pop/popmw/tx.go:39
github.com/gobuffalo/mw-paramlogger.parameterLogger.Middleware.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-paramlogger@v0.0.0-20181005191442-d6ee392ec72e/param_logger.go:63
github.com/gobuffalo/mw-contenttype.Set.func1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-contenttype@v0.0.0-20180802152300-74f5a47f4d56/content_type.go:11
github.com/gobuffalo/buffalo.sessionSaver.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/session.go:70
github.com/gobuffalo/buffalo.RequestLoggerFunc.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/request_logger.go:54
github.com/gobuffalo/buffalo.(*App).PanicHandler.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:82
github.com/gobuffalo/buffalo.(*App).defaultErrorMiddleware.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:88
github.com/gobuffalo/buffalo.RouteInfo.ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/route_info.go:108
github.com/gobuffalo/buffalo.(*RouteInfo).ServeHTTP
	<autogenerated>:1
github.com/gorilla/mux.(*Router).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gorilla/mux@v1.6.2/mux.go:162
github.com/markbates/refresh/refresh/web.ErrorChecker.func1
	/home/cippaciong/.go/pkg/mod/github.com/markbates/refresh@v1.4.11/refresh/web/web.go:23
net/http.HandlerFunc.ServeHTTP
	/usr/lib/go/src/net/http/server.go:1964
github.com/gobuffalo/buffalo.(*App).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/server.go:126
net/http.serverHandler.ServeHTTP
	/usr/lib/go/src/net/http/server.go:2741
net/http.(*conn).serve
	/usr/lib/go/src/net/http/server.go:1847
runtime.goexit
	/usr/lib/go/src/runtime/asm_amd64.s:1333
github.com/gobuffalo/pop.(*Connection).Transaction.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:130
github.com/gobuffalo/pop.(*postgresql).Lock
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/dialect_postgresql.go:183
github.com/gobuffalo/pop.(*Connection).Transaction
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/pop@v4.9.0+incompatible/connection.go:117
github.com/gobuffalo/buffalo-pop/pop/popmw.Transaction.func2.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo-pop@v1.1.13/pop/popmw/tx.go:39
github.com/gobuffalo/mw-paramlogger.parameterLogger.Middleware.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-paramlogger@v0.0.0-20181005191442-d6ee392ec72e/param_logger.go:63
github.com/gobuffalo/mw-contenttype.Set.func1.1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/mw-contenttype@v0.0.0-20180802152300-74f5a47f4d56/content_type.go:11
github.com/gobuffalo/buffalo.sessionSaver.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/session.go:70
github.com/gobuffalo/buffalo.RequestLoggerFunc.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/request_logger.go:54
github.com/gobuffalo/buffalo.(*App).PanicHandler.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:82
github.com/gobuffalo/buffalo.(*App).defaultErrorMiddleware.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:88
github.com/gobuffalo/buffalo.RouteInfo.ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/route_info.go:108
github.com/gobuffalo/buffalo.(*RouteInfo).ServeHTTP
	<autogenerated>:1
github.com/gorilla/mux.(*Router).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gorilla/mux@v1.6.2/mux.go:162
github.com/markbates/refresh/refresh/web.ErrorChecker.func1
	/home/cippaciong/.go/pkg/mod/github.com/markbates/refresh@v1.4.11/refresh/web/web.go:23
net/http.HandlerFunc.ServeHTTP
	/usr/lib/go/src/net/http/server.go:1964
github.com/gobuffalo/buffalo.(*App).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/server.go:126
net/http.serverHandler.ServeHTTP
	/usr/lib/go/src/net/http/server.go:2741
net/http.(*conn).serve
	/usr/lib/go/src/net/http/server.go:1847
runtime.goexit
	/usr/lib/go/src/runtime/asm_amd64.s:1333
github.com/gobuffalo/buffalo.sessionSaver.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/session.go:72
github.com/gobuffalo/buffalo.RequestLoggerFunc.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/request_logger.go:54
github.com/gobuffalo/buffalo.(*App).PanicHandler.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:82
github.com/gobuffalo/buffalo.(*App).defaultErrorMiddleware.func1
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/errors.go:88
github.com/gobuffalo/buffalo.RouteInfo.ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/route_info.go:108
github.com/gobuffalo/buffalo.(*RouteInfo).ServeHTTP
	<autogenerated>:1
github.com/gorilla/mux.(*Router).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gorilla/mux@v1.6.2/mux.go:162
github.com/markbates/refresh/refresh/web.ErrorChecker.func1
	/home/cippaciong/.go/pkg/mod/github.com/markbates/refresh@v1.4.11/refresh/web/web.go:23
net/http.HandlerFunc.ServeHTTP
	/usr/lib/go/src/net/http/server.go:1964
github.com/gobuffalo/buffalo.(*App).ServeHTTP
	/home/cippaciong/.go/pkg/mod/github.com/gobuffalo/buffalo@v0.13.4/server.go:126
net/http.serverHandler.ServeHTTP
	/usr/lib/go/src/net/http/server.go:2741
net/http.(*conn).serve
	/usr/lib/go/src/net/http/server.go:1847
runtime.goexit
	/usr/lib/go/src/runtime/asm_amd64.s:1333
@cippaciong
Copy link
Author

cippaciong commented Nov 19, 2018

Ok, I think I finally found out what is the problem here:
In associations/many_to_many_association.go inside the Constraint() method we have this code:

var columnFieldID string
i := reflect.Indirect(m.fieldValue)
if i.Kind() == reflect.Slice || i.Kind() == reflect.Array {
	t := i.Type().Elem()
	columnFieldID = fmt.Sprintf("%s%s", flect.Underscore(t.Name()), "_id")
} else {
	columnFieldID = fmt.Sprintf("%s%s", flect.Underscore(i.Type().Name()), "_id")
}

The problem here is that t.Name() returns an empty string if i is not an array of values but an array of pointers.
This is the output of logs I added to print various information:

2018/11/19 10:46:31 type: (many_to_many_association.go) []*models.Student
2018/11/19 10:46:31 kind: (many_to_many_association.go) slice
2018/11/19 10:46:31 elem: (many_to_many_association.go) *models.Student
2018/11/19 10:46:31 name: (many_to_many_association.go)
2018/11/19 10:46:31 pkg: (many_to_many_association.go)

A possible solution is check if kind of t.Elem() is a pointer and in that case add a second call to .Elem().

var columnFieldID string
i := reflect.Indirect(m.fieldValue)
if i.Kind() == reflect.Slice || i.Kind() == reflect.Array {
	t := i.Type().Elem()
	if t.Kind() == reflect.Ptr {
		columnFieldID = fmt.Sprintf("%s%s", flect.Underscore(t.Elem().Name()), "_id")
	} else {
		columnFieldID = fmt.Sprintf("%s%s", flect.Underscore(t.Name()), "_id")
	}
} else {
	t := i.Type()
	if t.Kind() == reflect.Ptr {
		columnFieldID = fmt.Sprintf("%s%s", flect.Underscore(t.Elem().Name()), "_id")
	} else {
		columnFieldID = fmt.Sprintf("%s%s", flect.Underscore(t.Name()), "_id")
	}
}

Logs:

2018/11/19 10:48:23 type: (many_to_many_association.go) []*models.Student
2018/11/19 10:48:23 kind: (many_to_many_association.go) slice
// Here I add a second call to `.Elem()`
2018/11/19 10:48:23 elem: (many_to_many_association.go) models.Student
2018/11/19 10:48:23 name: (many_to_many_association.go) Student
2018/11/19 10:48:23 pkg: (many_to_many_association.go) github.com/middleware2018-PSS/back2_school/models

@stanislas-m stanislas-m added the bug Something isn't working label Nov 19, 2018
@cippaciong
Copy link
Author

Hi, any news on this?
If there's anything I can do, just let me know 🙂

@stanislas-m
Copy link
Member

@cippaciong Sorry for the delay, this PR should fix your problem: #350

Thanks for the debugging work!

@cippaciong
Copy link
Author

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants