gorma icon indicating copy to clipboard operation
gorma copied to clipboard

HasOne fails to Preload in the helper.go file

Open jeffwillette opened this issue 8 years ago • 0 comments

I have a model with a HasOne relationship like this...

Model("Avatar", func() {
	Description("Avatar that will display by their name and profile")
	Field("id", gorma.Integer, func() {
		PrimaryKey()
	})
	Field("url", gorma.String)
})

Model("User", func() {
			Description("User model")
			HasOne("Avatar")
                        HasMany("Files")

and it fails to generate a helper function One[Model](ctx context.Context, id int) method

func (m *UserDB) OneProjectUser(ctx context.Context, id int) (*app.ProjectUser, error) {
	defer goa.MeasureSince([]string{"goa", "db", "projectUser", "oneprojectUser"}, time.Now())

	var native User
	err := m.Db.Scopes().Table(m.TableName()).Preload("Documents").Where("id = ?", id).Find(&native).Error

	if err != nil && err != gorm.ErrRecordNotFound {
		goa.LogError(ctx, "error getting User", "error", err.Error())
		return nil, err
	}

	view := *native.UserToProjectUser()
	return &view, err
}

jeffwillette avatar May 26 '17 14:05 jeffwillette