Fix name conflict bug in find
* Add more tests to test schema
This commit is contained in:
parent
cd7e45efaa
commit
0c44af51a8
2 changed files with 29 additions and 3 deletions
|
@ -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.
|
||||
|
|
26
testdata/test_schema.sql
vendored
26
testdata/test_schema.sql
vendored
|
@ -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)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue