Browse Source

Don't panic on empty units and units.PrepareFormulars()

Dmitry Yu Okunev 5 years ago
parent
commit
fcf26740c6
1 changed files with 8 additions and 0 deletions
  1. 8 0
      unit.go

+ 8 - 0
unit.go

@@ -221,6 +221,10 @@ func (u Unit) GetFormulars() Formulars {
 }
 
 func (units Units) PrepareFormulars(activeOnly bool) Units {
+	if len(units) == 0 {
+		return units
+	}
+
 	ids := units.GetUnitIds()
 	nums := units.GetPersNumbers()
 
@@ -230,6 +234,10 @@ func (units Units) PrepareFormulars(activeOnly bool) Units {
 		scope = scope.ActiveOnly()
 	}
 
+	if len(nums) == 0 && len(ids) == 0 {
+		return units
+	}
+
 	if len(nums) > 0 {
 		scope  = scope.Where("PersNumber IN (?) OR OrgDiv IN (?)", nums, ids)
 	} else {