Skip to content

HasOne fails to Preload in the helper.go file #152

Description

@jeffwillette

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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions