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

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

Open
jeffwillette opened this issue May 26, 2017 · 0 comments
Open

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

jeffwillette opened this issue May 26, 2017 · 0 comments

Comments

@jeffwillette
Copy link
Contributor

jeffwillette commented May 26, 2017

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant