Fix name conflict bug in find

* Add more tests to test schema
This commit is contained in:
Patrick O'brien 2016-08-21 16:03:51 +10:00
parent cd7e45efaa
commit 0c44af51a8
2 changed files with 29 additions and 3 deletions

View file

@ -22,7 +22,7 @@ func {{$tableNameSingular}}FindGP({{$pkArgs}}, selectCols ...string) *{{$tableNa
// {{$tableNameSingular}}Find retrieves a single record by ID with an executor. // {{$tableNameSingular}}Find retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns. // If selectCols is empty Find will return all columns.
func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) { func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}}Obj := &{{$tableNameSingular}}{}
sel := "*" sel := "*"
if len(selectCols) > 0 { if len(selectCols) > 0 {
@ -35,7 +35,7 @@ func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...s
q := boil.SQL(query, {{$pkNames | join ", "}}) q := boil.SQL(query, {{$pkNames | join ", "}})
boil.SetExecutor(q, exec) boil.SetExecutor(q, exec)
err := q.Bind({{$varNameSingular}}) err := q.Bind({{$varNameSingular}}Obj)
if err != nil { if err != nil {
if errors.Cause(err) == sql.ErrNoRows { if errors.Cause(err) == sql.ErrNoRows {
return nil, 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 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. // {{$tableNameSingular}}FindP retrieves a single record by ID with an executor, and panics on error.

View file

@ -135,3 +135,29 @@ create table spider_toys (
name character varying, name character varying,
primary key (spider_id) 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)
);