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

How to make the relationship? #77

Open
newerton opened this issue Apr 5, 2019 · 0 comments
Open

How to make the relationship? #77

newerton opened this issue Apr 5, 2019 · 0 comments

Comments

@newerton
Copy link

newerton commented Apr 5, 2019

Hello qiangxue, miss you on the Yii team.

I'm diversifying my portfolio, and improving my clients' APIs, I'm learning Go lang.

I followed several tutorials and blog about relationship, and I am 3 days without being able to make a BELONGS TO relationship.

What am I doing wrong, can you help me?

daos/product.go

func (dao *ProductDAO) Query(rs app.RequestScope, offset, limit int) ([]models.Product, error) {
	products := []models.Product{}
	err := rs.Tx().Select().
	                InnerJoin("establishment", dbx.NewExp("`product`.`establishment_id` = `establishment`.`id`")).
	                OrderBy("product.id").
	                Offset(int64(offset)).
	                Limit(int64(limit)).
	                All(&products)
	return products, err
}

models/product.go

type Product struct {
    Id int                                      `json:"id" db:"id"`
    Establishment       Establishment           `json:"establishment" db:"establishment"`
}

models/establishment.go

type Establishment struct {
    Id int                          `json:"id" db:"id"`
    Subtitle string                 `json:"subtitle" db:"subtitle"`
}
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