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

Bug in queries.MakeStructMapping when boil tag is boil:",bind" #1315

Open
sarthak opened this issue Oct 5, 2023 · 1 comment
Open

Bug in queries.MakeStructMapping when boil tag is boil:",bind" #1315

sarthak opened this issue Oct 5, 2023 · 1 comment

Comments

@sarthak
Copy link

sarthak commented Oct 5, 2023

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v4.10.2

What is your database and version (eg. Postgresql 10)

Doesn't matter

If this happened at runtime what code produced the issue? (if not applicable leave blank)

type struct JoinStruct {
  A struct {
    ColA string `boil:"cola"`
    ColB string `boil:"colb"`
  } `boil:",bind"
}

queries.MakeStructMapping(reflect.TypeOf(JoinStruct{}))

Further information. What did you do, what did you expect?

I expect bind mapping to be a map of form {"cola": .., "colb", ...}.
But in reality the map is of form {"a.cola": ..., "a.colb"}.

Thus the bug is that boil:",bind" behaves identical to boil:"<fieldname>,bind".

How to fix?

These lines are buggy --

tag, recurse := getBoilTag(f)
if len(tag) == 0 {
tag = unTitleCase(f.Name)
} else if tag[0] == '-' {
continue
}

Suggested patch is to replace if len(tag) == 0 if if len(tag) == 0 && !recurse.

@stephenafamo
Copy link
Collaborator

If you have identified where the issue is, kindly send in a PR with tests included to prevent a regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants