gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.8k stars 1.61k forks source link

cross-database queries are not well supported #3209

Closed jswxstw closed 1 month ago

jswxstw commented 11 months ago

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

go1.20.10 darwin/amd64

2. What version of GoFrame are you using?

v2.5.7

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

yes

4. What did you do?

table A: khaos_oss.resource_task table B: khaos_workflow.workflow_instance

There is a minor error shown as below:

func demo(ctx context.Context, resourceIds []string, statuses []string) (int, error) {
        var (
        orm             = dao.ResourceTask.Ctx(ctx).OmitEmptyWhere()
        taskColumns     = dao.ResourceTask.Columns()
        workflowColumns = dao.WorkflowInstance.Columns()
    )
    orm = orm.LeftJoin(fmt.Sprintf("%s.%s", dao.WorkflowInstance.DB().GetSchema(), dao.WorkflowInstance.Table()),
        fmt.Sprintf("%s.%s=%s.%s", dao.ResourceTask.Table(), taskColumns.WorkflowName,
            dao.WorkflowInstance.Table(), workflowColumns.Name))
    orm = orm.Where(do.ResourceTask{
        ResourceId: resourceIds,
    })
        orm = orm.Where(do.WorkflowInstance{
        Status: statuses,
    })
    return orm.Count()
}

The above code executes well and returns the result as expected, but logs show en error as below:

image

There is a fatal error shown as below:

func demo(ctx context.Context, limit int) error {
        var (
                 items          = []Item
        orm             = dao.ResourceTask.Ctx(ctx).OmitEmptyWhere()
        taskColumns     = dao.ResourceTask.Columns()
        workflowColumns = dao.WorkflowInstance.Columns()
    )
    orm = orm.FieldsPrefix(dao.ResourceTask.Table(), taskColumns)
        // Bug: columns in workflow_instance table except columns with the same name in resource_task table will not be add to the sql
        orm = orm.FieldsPrefix(dao.WorkflowInstance.Table(), workflowColumns)
        return orm.Limit(limit).Scan(&items) 
}

5. What did you expect to see?

6. What did you see instead?

gqcn commented 1 month ago

@jswxstw Hello there, sorry for late reply, as I missed some issues in my email. This issue might be fixed in my memory, please try the latest version of goframe, thanks for your feedback.