sqlboiler icon indicating copy to clipboard operation
sqlboiler copied to clipboard

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

Open sarthak opened this issue 8 months ago • 1 comments

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 -- https://github.com/volatiletech/sqlboiler/blob/644d45d0c780eab0b17a7da9e709c3cb10781768/queries/reflect.go#L395-L400

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

sarthak avatar Oct 05 '23 07:10 sarthak

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

stephenafamo avatar Nov 13 '23 15:11 stephenafamo