stash/pkg/manager/studio.go
WithoutPants 1e04deb3d4
Data layer restructuring (#997)
* Move query builders to sqlite package
* Add transaction system
* Wrap model resolvers in transaction
* Add error return value for StringSliceToIntSlice
* Update/refactor mutation resolvers
* Convert query builders
* Remove unused join types
* Add stash id unit tests
* Use WAL journal mode
2021-01-18 12:23:20 +11:00

34 lines
703 B
Go

package manager
import (
"errors"
"fmt"
"github.com/stashapp/stash/pkg/models"
)
func ValidateModifyStudio(studio models.StudioPartial, qb models.StudioReader) error {
if studio.ParentID == nil || !studio.ParentID.Valid {
return nil
}
// ensure there is no cyclic dependency
thisID := studio.ID
currentParentID := *studio.ParentID
for currentParentID.Valid {
if currentParentID.Int64 == int64(thisID) {
return errors.New("studio cannot be an ancestor of itself")
}
currentStudio, err := qb.Find(int(currentParentID.Int64))
if err != nil {
return fmt.Errorf("error finding parent studio: %s", err.Error())
}
currentParentID = currentStudio.ParentID
}
return nil
}