Files
gin-gonic-prepack/models/tenanted.go
🐙PiperYxzzy dd8d2a677d Added better Tenanting
* Removed Tenanting from base objects as some models may be tenantless
* Admins are naturally not restricted by tenants
* Users *ARE* the tenants (for now) so they don't require a tenant ID
either
* User-owned models should all include the Tenanted model as their base
* Created .Create and .Save methods attached to base model
2022-05-01 12:48:40 +02:00

22 lines
313 B
Go

package models
import (
"errors"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Tenanted struct {
Base
Tenant uuid.UUID `gorm:"index;<-:create"`
}
func (t *Tenanted) BeforeCreate(scope *gorm.DB) error {
if t.Tenant == uuid.Nil {
return errors.New("cannot save an untenanted object")
}
return nil
}