func (o *Storage) RemoveFilesG(related ...*File) error {
	return o.RemoveFiles(boil.GetDB(), related...)
}
RemoveFilesG relationships from objects passed in.
Removes related items from R.Files (uses pointer comparison, removal does not keep order)
Sets related.R.Storages.
Uses the global database handle.
package mdbmodels
import (
	"bytes"
	"database/sql"
	"fmt"
	"reflect"
	"strings"
	"sync"
	"time"
	"github.com/Bnei-Baruch/sqlboiler/boil"
	"github.com/Bnei-Baruch/sqlboiler/queries"
	"github.com/Bnei-Baruch/sqlboiler/queries/qm"
	"github.com/Bnei-Baruch/sqlboiler/strmangle"
	"github.com/pkg/errors"
)
type Storage struct {
	ID       int64  `boil:"id" json:"id" toml:"id" yaml:"id"`
	Name     string `boil:"name" json:"name" toml:"name" yaml:"name"`
	Country  string `boil:"country" json:"country" toml:"country" yaml:"country"`
	Location string `boil:"location" json:"location" toml:"location" yaml:"location"`
	Status   string `boil:"status" json:"status" toml:"status" yaml:"status"`
	Access   string `boil:"access" json:"access" toml:"access" yaml:"access"`
	R *storageR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L storageL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var StorageColumns = struct {
	ID       string
	Name     string
	Country  string
	Location string
	Status   string
	Access   string
}{
	ID:       "id",
	Name:     "name",
	Country:  "country",
	Location: "location",
	Status:   "status",
	Access:   "access",
}
type storageR struct {
	Files FileSlice
}
type storageL struct{}
var (
	storageColumns               = []string{"id", "name", "country", "location", "status", "access"}
	storageColumnsWithoutDefault = []string{"name", "country", "location", "status", "access"}
	storageColumnsWithDefault    = []string{"id"}
	storagePrimaryKeyColumns     = []string{"id"}
)
type (
	StorageSlice []*Storage
	storageQuery struct {
		*queries.Query
	}
)
var (
	storageType                 = reflect.TypeOf(&Storage{})
	storageMapping              = queries.MakeStructMapping(storageType)
	storagePrimaryKeyMapping, _ = queries.BindMapping(storageType, storageMapping, storagePrimaryKeyColumns)
	storageInsertCacheMut       sync.RWMutex
	storageInsertCache          = make(map[string]insertCache)
	storageUpdateCacheMut       sync.RWMutex
	storageUpdateCache          = make(map[string]updateCache)
	storageUpsertCacheMut       sync.RWMutex
	storageUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q storageQuery) OneP() *Storage {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q storageQuery) One() (*Storage, error) {
	o := &Storage{}
	queries.SetLimit(q.Query, 1)
	err := q.Bind(o)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: failed to execute a one query for storages")
	}
	return o, nil
}
func (q storageQuery) AllP() StorageSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q storageQuery) All() (StorageSlice, error) {
	var o []*Storage
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to Storage slice")
	}
	return o, nil
}
func (q storageQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q storageQuery) Count() (int64, error) {
	var count int64
	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)
	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return 0, errors.Wrap(err, "mdbmodels: failed to count storages rows")
	}
	return count, nil
}
func (q storageQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q storageQuery) Exists() (bool, error) {
	var count int64
	queries.SetCount(q.Query)
	queries.SetLimit(q.Query, 1)
	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return false, errors.Wrap(err, "mdbmodels: failed to check if storages exists")
	}
	return count > 0, nil
}
func (o *Storage) FilesG(mods ...qm.QueryMod) fileQuery {
	return o.Files(boil.GetDB(), mods...)
}
func (o *Storage) Files(exec boil.Executor, mods ...qm.QueryMod) fileQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.InnerJoin("\"files_storages\" on \"files\".\"id\" = \"files_storages\".\"file_id\""),
		qm.Where("\"files_storages\".\"storage_id\"=?", o.ID),
	)
	query := Files(exec, queryMods...)
	queries.SetFrom(query.Query, "\"files\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"files\".*"})
	}
	return query
}
func (storageL) LoadFiles(e boil.Executor, singular bool, maybeStorage interface{}) error {
	var slice []*Storage
	var object *Storage
	count := 1
	if singular {
		object = maybeStorage.(*Storage)
	} else {
		slice = *maybeStorage.(*[]*Storage)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &storageR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &storageR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select \"a\".*, \"b\".\"storage_id\" from \"files\" as \"a\" inner join \"files_storages\" as \"b\" on \"a\".\"id\" = \"b\".\"file_id\" where \"b\".\"storage_id\" in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
	)
	if boil.DebugMode {
		fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
	}
	results, err := e.Query(query, args...)
	if err != nil {
		return errors.Wrap(err, "failed to eager load files")
	}
	defer results.Close()
	var resultSlice []*File
	var localJoinCols []int64
	for results.Next() {
		one := new(File)
		var localJoinCol int64
		err = results.Scan(&one.ID, &one.UID, &one.Name, &one.Size, &one.Type, &one.SubType, &one.MimeType, &one.Sha1, &one.ContentUnitID, &one.CreatedAt, &one.Language, &one.BackupCount, &one.FirstBackupTime, &one.Properties, &one.ParentID, &one.FileCreatedAt, &one.Secure, &one.Published, &one.RemovedAt, &localJoinCol)
		if err = results.Err(); err != nil {
			return errors.Wrap(err, "failed to plebian-bind eager loaded slice files")
		}
		resultSlice = append(resultSlice, one)
		localJoinCols = append(localJoinCols, localJoinCol)
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "failed to plebian-bind eager loaded slice files")
	}
	if singular {
		object.R.Files = resultSlice
		return nil
	}
	for i, foreign := range resultSlice {
		localJoinCol := localJoinCols[i]
		for _, local := range slice {
			if local.ID == localJoinCol {
				local.R.Files = append(local.R.Files, foreign)
				break
			}
		}
	}
	return nil
}
func (o *Storage) AddFilesG(insert bool, related ...*File) error {
	return o.AddFiles(boil.GetDB(), insert, related...)
}
func (o *Storage) AddFilesP(exec boil.Executor, insert bool, related ...*File) {
	if err := o.AddFiles(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Storage) AddFilesGP(insert bool, related ...*File) {
	if err := o.AddFiles(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Storage) AddFiles(exec boil.Executor, insert bool, related ...*File) error {
	var err error
	for _, rel := range related {
		if insert {
			if err = rel.Insert(exec); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		}
	}
	for _, rel := range related {
		query := "insert into \"files_storages\" (\"storage_id\", \"file_id\") values ($1, $2)"
		values := []interface{}{o.ID, rel.ID}
		if boil.DebugMode {
			fmt.Fprintln(boil.DebugWriter, query)
			fmt.Fprintln(boil.DebugWriter, values)
		}
		_, err = exec.Exec(query, values...)
		if err != nil {
			return errors.Wrap(err, "failed to insert into join table")
		}
	}
	if o.R == nil {
		o.R = &storageR{
			Files: related,
		}
	} else {
		o.R.Files = append(o.R.Files, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &fileR{
				Storages: StorageSlice{o},
			}
		} else {
			rel.R.Storages = append(rel.R.Storages, o)
		}
	}
	return nil
}
func (o *Storage) SetFilesG(insert bool, related ...*File) error {
	return o.SetFiles(boil.GetDB(), insert, related...)
}
func (o *Storage) SetFilesP(exec boil.Executor, insert bool, related ...*File) {
	if err := o.SetFiles(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Storage) SetFilesGP(insert bool, related ...*File) {
	if err := o.SetFiles(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Storage) SetFiles(exec boil.Executor, insert bool, related ...*File) error {
	query := "delete from \"files_storages\" where \"storage_id\" = $1"
	values := []interface{}{o.ID}
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, query)
		fmt.Fprintln(boil.DebugWriter, values)
	}
	_, err := exec.Exec(query, values...)
	if err != nil {
		return errors.Wrap(err, "failed to remove relationships before set")
	}
	removeFilesFromStoragesSlice(o, related)
	if o.R != nil {
		o.R.Files = nil
	}
	return o.AddFiles(exec, insert, related...)
}