go-pg/pg

Model "does not have relation" on bulk insert/update

masterentropy opened this issue · 0 comments

I am using the bulk insert/update feature, by passing in an array of values into the library. My tables and types look like:

type Shape struct {
	tableName models.TableName `pg:"shapes"`
	ID                   string          `pg:"id,pk"`
        UserID           string          `pg:"user_id,notnull"`

	ShapeType    *ShapeType
}

And my bulk insert statement:

shapes *[]*Shape
db.Model(shapes).Returning("*").Insert()

I get the error:

model=Shape does not have relation="ShapeType"

I found that I can ignore this field by using pg:"-", but doing this now gives me the same error as above when doing SELECT on the table:

db.Model(&shape).Where("user_id = ?", userID).Relation("ShapeType").Select()

My SELECT statement worked just fine without pg:"-" before. I can get either one statement or another working, but not both. If I am doing something incorrectly, what is it?

Context (Environment)

I am using go-pg v9.1.6