diff --git a/CHANGELOG.md b/CHANGELOG.md index 10a715a60..0058271b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## (WIP) v0.15.2 -- Fixed view query `SELECT DISTINCT` identifiers parsing ([#2349](https://github.com/pocketbase/pocketbase/discussions/2349#discussioncomment-5706019)). +- Fixed View query `SELECT DISTINCT` identifiers parsing ([#2349-5706019](https://github.com/pocketbase/pocketbase/discussions/2349#discussioncomment-5706019)). + +- Fixed View collection schema incorrectly resolving multiple aliased fields originating from the same field source ([#2349-5707675](https://github.com/pocketbase/pocketbase/discussions/2349#discussioncomment-5707675)). ## v0.15.1 diff --git a/daos/view.go b/daos/view.go index 22443225a..0181ee0f0 100644 --- a/daos/view.go +++ b/daos/view.go @@ -311,6 +311,7 @@ func (dao *Dao) parseQueryToFields(selectQuery string) (map[string]*queryField, if field != nil { clone := *field + clone.Id = "" // unset to prevent duplications if the same field is aliased multiple times clone.Name = col.alias result[col.alias] = &queryField{ field: &clone, diff --git a/daos/view_test.go b/daos/view_test.go index c2b6c3235..a47fb0160 100644 --- a/daos/view_test.go +++ b/daos/view_test.go @@ -395,8 +395,7 @@ func TestCreateViewSchema(t *testing.T) { created created_alias, updated updated_alias, 123 as custom - from demo1 - `, + from demo1`, false, map[string]string{ "id2": schema.FieldTypeRelation, @@ -415,14 +414,31 @@ func TestCreateViewSchema(t *testing.T) { id as id2, id, 123 as custom - from demo1 - `, + from demo1`, false, map[string]string{ "id2": schema.FieldTypeRelation, "custom": schema.FieldTypeJson, }, }, + { + "query with aliasing the same field multiple times", + `select + a.id as id, + a.text as alias1, + a.text as alias2, + b.text as alias3, + b.text as alias4 + from demo1 a + left join demo1 as b`, + false, + map[string]string{ + "alias1": schema.FieldTypeText, + "alias2": schema.FieldTypeText, + "alias3": schema.FieldTypeText, + "alias4": schema.FieldTypeText, + }, + }, } for _, s := range scenarios {