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

Orm table connection query, specify the query field, the error field is blurred #2851

Closed
tuye01 opened this issue Aug 9, 2023 · 1 comment
Labels

Comments

@tuye01
Copy link

tuye01 commented Aug 9, 2023

1. What version of Go and system type/arch are you using?

go1.17 windows/386

2. What version of GoFrame are you using?

v2.5.0

3. Can this issue be re-produced with the latest release?

v2.5.1仍存在

4. What did you do?

	err := dao. TInfIdpClient.Ctx(ctx).
		Fields(dao. TInfIdpClient.Columns(). Id, dao. TInfIdp.Columns(). NameCn, dao. TInfIdp.Columns(). SourceType).
		LeftJoin(dao. TInfIdp.Table(), "idp", "t_inf_idp_client.idp_id =idp.id").
		Where(dao. TInfIdp.Columns(). Deleted, consts. DataDeletedFalse).
		Where(dao. TInfIdp.Columns(). Enabled, consts. DataEnabled).
		Scan(&idpData)
	if err != nil {
		return nil, err
	}

sql:

SELECT `id` FROM `t_inf_idp_client` LEFT JOIN `t_inf_idp` AS `idp` ON (t_inf_idp_client.idp_id =idp.id) WHERE 
        (`t_inf_idp_client`.`deleted`=0) AND (`t_inf_idp_client`.`enabled`=1)

error message:Column 'id' in field list is ambiguous

5. What did you expect to see?

1.连表中的关联关系使用代码生成的字段变量对比
LeftJoin(dao. TInfIdp.Table(), "idp", "t_inf_idp_client.idp_id =idp.id")
==》
LeftJoin(dao. TInfIdp.Table(), dao. TInfIdpClient.Columns(). IdpId==dao. TInfIdp.Columns(). Id).
2.连表时可指定查询 某个表中的字段

6. What did you see instead?

@Issues-translate-bot Issues-translate-bot changed the title Orm 连表查询 指定查询字段 报错字段模糊 Orm table connection query, specify the query field, the error field is blurred Aug 9, 2023
@gqcn
Copy link
Member

gqcn commented Oct 7, 2023

@tuye01 Please use like this:

err := dao.TInfIdpClient.Ctx(ctx).
	FieldsPrefix(dao.TInfIdpClient.Table(), dao.TInfIdpClient.Columns().Id).
	FieldsPrefix(dao.TInfIdp.Table(), dao.TInfIdp.Columns().NameCn).
	FieldsPrefix(dao.TInfIdp.Table(), dao.TInfIdp.Columns().SourceType).
	LeftJoinOnFields(dao.TInfIdp.Table(), "idp", "=", "id").
	Where(do.TInfIdp{
		Deleted: consts.DataDeletedFalse,
		Enabled: consts.DataEnabled,
	})
	Scan(&idpData)
if err != nil {
	return nil, err
}

@gqcn gqcn added the question label Oct 7, 2023
@gqcn gqcn closed this as completed Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants