coopernurse/gorp — pull request #94 by nelsam (2013-11-08 19:01:38+00:00)
Title: Overridden struct fields

I have a situation where I want to use a struct from an external library in my models, but slightly modify some of its fields before mapping it to a database table. The base struct includes fields that are interface types, and I want my struct to override those interface types with some of my own models, so that I can use the zero values for the purposes of FromDb. However, since my overridden fields are the same name as the embedded struct's fields, gorp blows up when generating queries because it queries the same column twice.

I added a very simple test for the Invoice struct, for a case where the Id field is overridden with a string Id. Mapping that overridden Invoice struct causes the tests to fail.

The second commit is a fix for the issue. It may not be the best way to fix that issue, but it works, and the tests pass (with the postgres dialect, at least). Let me know if anything I'm doing is particularly stupid; but it seems to be a use case worth supporting, from my perspective.

Of course, my perspective is biased, because I'm the one with that use case.