Draft: fix JSONType[T] Pluck query error #201
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What did this pull request do?
This is a fix MR for #200
and this cause a little breaking change in JSONType[T] usage
the bug
I ever post PR #174 , but I didn't have test enough for ALL gorm query API.
this exported
Data T
field worked well inFind
,First
method, and added in json_type_test.go.and
Data() T
method is not so efficient than directly exported field , but it is wrong.This issue #200 give a bad case query in
Pluck
Gorm found the input ptr of value
var field = &JSONType[*User]
is a struct , and have an exported FieldData T
so it goto the this Struct's schema.Fields logic, and found this struct's
Data T
and checkedfield.DataType == ""
https://github.com/go-gorm/gorm/blob/532e9cf4ccce927249bcb102c09e4a9093aae4fe/schema/schema.go#L280-L283
so finally got an error
the fix
I research the gorm and found it only collect
ast.IsExported
Field to scheme.Fieldsand the
JSONType[T]
provide generic methodValuer
andScaner
is only for a field not for another relation Table.so I think make
Data
unexported is a better fix solution.what about the breaking change
I this this breaking is small, and easy enough to change
If same name is not ok. may be change to
result.GetData()
Feel sorry to introduce some bug and cause a break change😢
User Case Description
Note for JSONSlice[T]
sadly
db.Pluck
still failed for JSONSlice[T] dest, because gorm will reflect the dest and process the Array and Sliceso, I add a
Note
in README.md for JSONSlice[T]