Skip to content

Conversation

wln32
Copy link
Member

@wln32 wln32 commented May 4, 2024

gstructs.Type.FieldKeys() 无法识别匿名结构体的字段,导致带有With的查询时,查询的字段不符合期望 #2119

@wln32 wln32 requested a review from gqcn May 4, 2024 14:25
if t.Kind() != reflect.Struct {
return []string{}
}
return getStructFields(t.Type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不能直接改这个基础方法,根据issue描述,似乎是这里没有获取到匿名结构体的Field。这里有一个RecursiveOption的控制你可以研究一下呢?
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gqcn 这里获取的是最外层结构体,
123456

所以那里是无法获取到Status结构体的字段

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不能直接改这个基础方法,根据issue描述,似乎是这里没有获取到匿名结构体的Field。这里有一个

倒是可以使用gstructs包的其他方法来解析结构体获取所有的字段,当时我看那个方法只有这里使用了,所以就做了改动。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gqcn 这里获取的是最外层结构体, 123456

所以那里是无法获取到Status结构体的字段

那截图红框部分没有达到预期,预期是如果内嵌的结构体在没有tag时嵌套结构体的属性会作为Fields返回。可以研究下这个方法为什么失败了呢?

if t.Kind() != reflect.Struct {
return []string{}
}
return getStructFields(t.Type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gqcn 这里获取的是最外层结构体, 123456

所以那里是无法获取到Status结构体的字段

那截图红框部分没有达到预期,预期是如果内嵌的结构体在没有tag时嵌套结构体的属性会作为Fields返回。可以研究下这个方法为什么失败了呢?

wln32 and others added 3 commits July 4, 2024 15:03
@@ -347,21 +347,6 @@ func Test_StructTypeBySlice(t *testing.T) {
})
}

func TestType_FieldKeys(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要删掉呢?

@gqcn
Copy link
Member

gqcn commented Dec 5, 2024

这个PR漏掉了,我新开了分支合并了这个PR内容并做了一些完善 #4011

@gqcn gqcn closed this Dec 5, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


This PR was missed, I opened a new branch to merge the content of this PR and made some improvements #4011

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

Successfully merging this pull request may close these issues.

WithAll().Scan(&list) can't fetch embedded struct from HasOne relation's children table
3 participants