Browse Source

Don't panic if no rows

Dmitry Yu Okunev 5 years ago
parent
commit
c00dbeacae
3 changed files with 4 additions and 4 deletions
  1. 2 2
      formular.go
  2. 1 1
      person.go
  3. 1 1
      unit.go

+ 2 - 2
formular.go

@@ -76,7 +76,7 @@ func (f Formular) View_readTag(fieldName string, parent interface{}, args []inte
 func (f *Formular) PrepareUnit() *Formular {
 	var err error
 	f.unit, err = UnitSQL.First(Unit{Id: f.UnitId})
-	if err != nil {
+	if err != nil && err != sql.ErrNoRows {
 		revel.ERROR.Printf("Got error: %v", err.Error())
 		return f
 	}
@@ -94,7 +94,7 @@ func (f Formular) GetUnit() Unit {
 func (f *Formular) PreparePerson() *Formular {
 	var err error
 	f.person, err = PersonSQL.First(Person{EmpGUID: f.EmpGUID})
-	if err != nil {
+	if err != nil && err != sql.ErrNoRows {
 		revel.ERROR.Printf("Got error: %v", err.Error())
 		return f
 	}

+ 1 - 1
person.go

@@ -71,7 +71,7 @@ func (people People) GetEmpGUIDs() (empGUIDs []int) {
 func (person *Person) PrepareFormulars() *Person {
 	var err error
 	person.formulars, err = FormularSQL.Select(Formular{EmpGUID: person.EmpGUID})
-	if err != nil {
+	if err != nil && err != sql.ErrNoRows {
 		panic(err)
 	}
 

+ 1 - 1
unit.go

@@ -158,7 +158,7 @@ func (u Unit) GetChildrenPtrs() []*Unit {
 func (u *Unit) PrepareFormulars() *Unit {
 	var err error
 	u.formulars, err = FormularSQL.Select(Formular{UnitId: u.Id})
-	if err != nil {
+	if err != nil && err != sql.ErrNoRows {
 		panic(err)
 	}