From 0c44af51a819341702067558ae4a54e2b6191b25 Mon Sep 17 00:00:00 2001 From: Patrick O'brien Date: Sun, 21 Aug 2016 16:03:51 +1000 Subject: [PATCH] Fix name conflict bug in find * Add more tests to test schema --- templates/09_find.tpl | 6 +++--- testdata/test_schema.sql | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/templates/09_find.tpl b/templates/09_find.tpl index 3f5bff3..0521132 100644 --- a/templates/09_find.tpl +++ b/templates/09_find.tpl @@ -22,7 +22,7 @@ func {{$tableNameSingular}}FindGP({{$pkArgs}}, selectCols ...string) *{{$tableNa // {{$tableNameSingular}}Find retrieves a single record by ID with an executor. // If selectCols is empty Find will return all columns. func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) { - {{$varNameSingular}} := &{{$tableNameSingular}}{} + {{$varNameSingular}}Obj := &{{$tableNameSingular}}{} sel := "*" if len(selectCols) > 0 { @@ -35,7 +35,7 @@ func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...s q := boil.SQL(query, {{$pkNames | join ", "}}) boil.SetExecutor(q, exec) - err := q.Bind({{$varNameSingular}}) + err := q.Bind({{$varNameSingular}}Obj) if err != nil { if errors.Cause(err) == sql.ErrNoRows { return nil, sql.ErrNoRows @@ -43,7 +43,7 @@ func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...s return nil, errors.Wrap(err, "{{.PkgName}}: unable to select from {{.Table.Name}}") } - return {{$varNameSingular}}, nil + return {{$varNameSingular}}Obj, nil } // {{$tableNameSingular}}FindP retrieves a single record by ID with an executor, and panics on error. diff --git a/testdata/test_schema.sql b/testdata/test_schema.sql index 3d63851..65b786d 100644 --- a/testdata/test_schema.sql +++ b/testdata/test_schema.sql @@ -135,3 +135,29 @@ create table spider_toys ( name character varying, primary key (spider_id) ); + +/* + Test: + * Variations of capitalization + * Single value columns + * Primary key as only value +*/ +create table pals ( + pal character varying, + primary key (pal) +); + +create table friend ( + friend character varying, + primary key (friend) +); + +create table bro ( + bros character varying, + primary key (bros) +); + +create table enemies ( + enemies character varying, + primary key (enemies) +);