func (o *File) SetParentGP(insert bool, related *File) {
	if err := o.SetParent(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
SetParentGP of the file to the related item.
Sets o.R.Parent to related.
Adds o to related.R.ParentFiles.
Uses the global database handle and panics on error.
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"
	"gopkg.in/volatiletech/null.v6"
)
type File struct {
	ID              int64       `boil:"id" json:"id" toml:"id" yaml:"id"`
	UID             string      `boil:"uid" json:"uid" toml:"uid" yaml:"uid"`
	Name            string      `boil:"name" json:"name" toml:"name" yaml:"name"`
	Size            int64       `boil:"size" json:"size" toml:"size" yaml:"size"`
	Type            string      `boil:"type" json:"type" toml:"type" yaml:"type"`
	SubType         string      `boil:"sub_type" json:"sub_type" toml:"sub_type" yaml:"sub_type"`
	MimeType        null.String `boil:"mime_type" json:"mime_type,omitempty" toml:"mime_type" yaml:"mime_type,omitempty"`
	Sha1            null.Bytes  `boil:"sha1" json:"sha1,omitempty" toml:"sha1" yaml:"sha1,omitempty"`
	ContentUnitID   null.Int64  `boil:"content_unit_id" json:"content_unit_id,omitempty" toml:"content_unit_id" yaml:"content_unit_id,omitempty"`
	CreatedAt       time.Time   `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	Language        null.String `boil:"language" json:"language,omitempty" toml:"language" yaml:"language,omitempty"`
	BackupCount     null.Int16  `boil:"backup_count" json:"backup_count,omitempty" toml:"backup_count" yaml:"backup_count,omitempty"`
	FirstBackupTime null.Time   `boil:"first_backup_time" json:"first_backup_time,omitempty" toml:"first_backup_time" yaml:"first_backup_time,omitempty"`
	Properties      null.JSON   `boil:"properties" json:"properties,omitempty" toml:"properties" yaml:"properties,omitempty"`
	ParentID        null.Int64  `boil:"parent_id" json:"parent_id,omitempty" toml:"parent_id" yaml:"parent_id,omitempty"`
	FileCreatedAt   null.Time   `boil:"file_created_at" json:"file_created_at,omitempty" toml:"file_created_at" yaml:"file_created_at,omitempty"`
	Secure          int16       `boil:"secure" json:"secure" toml:"secure" yaml:"secure"`
	Published       bool        `boil:"published" json:"published" toml:"published" yaml:"published"`
	RemovedAt       null.Time   `boil:"removed_at" json:"removed_at,omitempty" toml:"removed_at" yaml:"removed_at,omitempty"`
	R *fileR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L fileL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var FileColumns = struct {
	ID              string
	UID             string
	Name            string
	Size            string
	Type            string
	SubType         string
	MimeType        string
	Sha1            string
	ContentUnitID   string
	CreatedAt       string
	Language        string
	BackupCount     string
	FirstBackupTime string
	Properties      string
	ParentID        string
	FileCreatedAt   string
	Secure          string
	Published       string
	RemovedAt       string
}{
	ID:              "id",
	UID:             "uid",
	Name:            "name",
	Size:            "size",
	Type:            "type",
	SubType:         "sub_type",
	MimeType:        "mime_type",
	Sha1:            "sha1",
	ContentUnitID:   "content_unit_id",
	CreatedAt:       "created_at",
	Language:        "language",
	BackupCount:     "backup_count",
	FirstBackupTime: "first_backup_time",
	Properties:      "properties",
	ParentID:        "parent_id",
	FileCreatedAt:   "file_created_at",
	Secure:          "secure",
	Published:       "published",
	RemovedAt:       "removed_at",
}
type fileR struct {
	ContentUnit *ContentUnit
	Parent      *File
	ParentFiles FileSlice
	Operations  OperationSlice
	Storages    StorageSlice
}
type fileL struct{}
var (
	fileColumns               = []string{"id", "uid", "name", "size", "type", "sub_type", "mime_type", "sha1", "content_unit_id", "created_at", "language", "backup_count", "first_backup_time", "properties", "parent_id", "file_created_at", "secure", "published", "removed_at"}
	fileColumnsWithoutDefault = []string{"uid", "name", "size", "type", "sub_type", "mime_type", "sha1", "content_unit_id", "language", "first_backup_time", "properties", "parent_id", "file_created_at", "removed_at"}
	fileColumnsWithDefault    = []string{"id", "created_at", "backup_count", "secure", "published"}
	filePrimaryKeyColumns     = []string{"id"}
)
type (
	FileSlice []*File
	fileQuery struct {
		*queries.Query
	}
)
var (
	fileType                 = reflect.TypeOf(&File{})
	fileMapping              = queries.MakeStructMapping(fileType)
	filePrimaryKeyMapping, _ = queries.BindMapping(fileType, fileMapping, filePrimaryKeyColumns)
	fileInsertCacheMut       sync.RWMutex
	fileInsertCache          = make(map[string]insertCache)
	fileUpdateCacheMut       sync.RWMutex
	fileUpdateCache          = make(map[string]updateCache)
	fileUpsertCacheMut       sync.RWMutex
	fileUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q fileQuery) OneP() *File {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q fileQuery) One() (*File, error) {
	o := &File{}
	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 files")
	}
	return o, nil
}
func (q fileQuery) AllP() FileSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q fileQuery) All() (FileSlice, error) {
	var o []*File
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to File slice")
	}
	return o, nil
}
func (q fileQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q fileQuery) 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 files rows")
	}
	return count, nil
}
func (q fileQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q fileQuery) 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 files exists")
	}
	return count > 0, nil
}
func (o *File) ContentUnitG(mods ...qm.QueryMod) contentUnitQuery {
	return o.ContentUnit(boil.GetDB(), mods...)
}
func (o *File) ContentUnit(exec boil.Executor, mods ...qm.QueryMod) contentUnitQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.ContentUnitID),
	}
	queryMods = append(queryMods, mods...)
	query := ContentUnits(exec, queryMods...)
	queries.SetFrom(query.Query, "\"content_units\"")
	return query
}
func (o *File) ParentG(mods ...qm.QueryMod) fileQuery {
	return o.Parent(boil.GetDB(), mods...)
}
func (o *File) Parent(exec boil.Executor, mods ...qm.QueryMod) fileQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.ParentID),
	}
	queryMods = append(queryMods, mods...)
	query := Files(exec, queryMods...)
	queries.SetFrom(query.Query, "\"files\"")
	return query
}
func (o *File) ParentFilesG(mods ...qm.QueryMod) fileQuery {
	return o.ParentFiles(boil.GetDB(), mods...)
}
func (o *File) ParentFiles(exec boil.Executor, mods ...qm.QueryMod) fileQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"files\".\"parent_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 (o *File) OperationsG(mods ...qm.QueryMod) operationQuery {
	return o.Operations(boil.GetDB(), mods...)
}
func (o *File) Operations(exec boil.Executor, mods ...qm.QueryMod) operationQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.InnerJoin("\"files_operations\" on \"operations\".\"id\" = \"files_operations\".\"operation_id\""),
		qm.Where("\"files_operations\".\"file_id\"=?", o.ID),
	)
	query := Operations(exec, queryMods...)
	queries.SetFrom(query.Query, "\"operations\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"operations\".*"})
	}
	return query
}
func (o *File) StoragesG(mods ...qm.QueryMod) storageQuery {
	return o.Storages(boil.GetDB(), mods...)
}
func (o *File) Storages(exec boil.Executor, mods ...qm.QueryMod) storageQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.InnerJoin("\"files_storages\" on \"storages\".\"id\" = \"files_storages\".\"storage_id\""),
		qm.Where("\"files_storages\".\"file_id\"=?", o.ID),
	)
	query := Storages(exec, queryMods...)
	queries.SetFrom(query.Query, "\"storages\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"storages\".*"})
	}
	return query
}
func (fileL) LoadContentUnit(e boil.Executor, singular bool, maybeFile interface{}) error {
	var slice []*File
	var object *File
	count := 1
	if singular {
		object = maybeFile.(*File)
	} else {
		slice = *maybeFile.(*[]*File)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &fileR{}
		}
		args[0] = object.ContentUnitID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &fileR{}
			}
			args[i] = obj.ContentUnitID
		}
	}
	query := fmt.Sprintf(
		"select * from \"content_units\" where \"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 ContentUnit")
	}
	defer results.Close()
	var resultSlice []*ContentUnit
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice ContentUnit")
	}
	if len(resultSlice) == 0 {
		return nil
	}
	if singular {
		object.R.ContentUnit = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.ContentUnitID.Int64 == foreign.ID {
				local.R.ContentUnit = foreign
				break
			}
		}
	}
	return nil
}
func (fileL) LoadParent(e boil.Executor, singular bool, maybeFile interface{}) error {
	var slice []*File
	var object *File
	count := 1
	if singular {
		object = maybeFile.(*File)
	} else {
		slice = *maybeFile.(*[]*File)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &fileR{}
		}
		args[0] = object.ParentID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &fileR{}
			}
			args[i] = obj.ParentID
		}
	}
	query := fmt.Sprintf(
		"select * from \"files\" where \"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 File")
	}
	defer results.Close()
	var resultSlice []*File
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice File")
	}
	if len(resultSlice) == 0 {
		return nil
	}
	if singular {
		object.R.Parent = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.ParentID.Int64 == foreign.ID {
				local.R.Parent = foreign
				break
			}
		}
	}
	return nil
}
func (fileL) LoadParentFiles(e boil.Executor, singular bool, maybeFile interface{}) error {
	var slice []*File
	var object *File
	count := 1
	if singular {
		object = maybeFile.(*File)
	} else {
		slice = *maybeFile.(*[]*File)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &fileR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &fileR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"files\" where \"parent_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
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice files")
	}
	if singular {
		object.R.ParentFiles = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.ParentID.Int64 {
				local.R.ParentFiles = append(local.R.ParentFiles, foreign)
				break
			}
		}
	}
	return nil
}
func (fileL) LoadOperations(e boil.Executor, singular bool, maybeFile interface{}) error {
	var slice []*File
	var object *File
	count := 1
	if singular {
		object = maybeFile.(*File)
	} else {
		slice = *maybeFile.(*[]*File)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &fileR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &fileR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select \"a\".*, \"b\".\"file_id\" from \"operations\" as \"a\" inner join \"files_operations\" as \"b\" on \"a\".\"id\" = \"b\".\"operation_id\" where \"b\".\"file_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 operations")
	}
	defer results.Close()
	var resultSlice []*Operation
	var localJoinCols []int64
	for results.Next() {
		one := new(Operation)
		var localJoinCol int64
		err = results.Scan(&one.ID, &one.UID, &one.TypeID, &one.CreatedAt, &one.Station, &one.UserID, &one.Details, &one.Properties, &localJoinCol)
		if err = results.Err(); err != nil {
			return errors.Wrap(err, "failed to plebian-bind eager loaded slice operations")
		}
		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 operations")
	}
	if singular {
		object.R.Operations = resultSlice
		return nil
	}
	for i, foreign := range resultSlice {
		localJoinCol := localJoinCols[i]
		for _, local := range slice {
			if local.ID == localJoinCol {
				local.R.Operations = append(local.R.Operations, foreign)
				break
			}
		}
	}
	return nil
}
func (fileL) LoadStorages(e boil.Executor, singular bool, maybeFile interface{}) error {
	var slice []*File
	var object *File
	count := 1
	if singular {
		object = maybeFile.(*File)
	} else {
		slice = *maybeFile.(*[]*File)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &fileR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &fileR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select \"a\".*, \"b\".\"file_id\" from \"storages\" as \"a\" inner join \"files_storages\" as \"b\" on \"a\".\"id\" = \"b\".\"storage_id\" where \"b\".\"file_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 storages")
	}
	defer results.Close()
	var resultSlice []*Storage
	var localJoinCols []int64
	for results.Next() {
		one := new(Storage)
		var localJoinCol int64
		err = results.Scan(&one.ID, &one.Name, &one.Country, &one.Location, &one.Status, &one.Access, &localJoinCol)
		if err = results.Err(); err != nil {
			return errors.Wrap(err, "failed to plebian-bind eager loaded slice storages")
		}
		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 storages")
	}
	if singular {
		object.R.Storages = resultSlice
		return nil
	}
	for i, foreign := range resultSlice {
		localJoinCol := localJoinCols[i]
		for _, local := range slice {
			if local.ID == localJoinCol {
				local.R.Storages = append(local.R.Storages, foreign)
				break
			}
		}
	}
	return nil
}
func (o *File) SetContentUnitG(insert bool, related *ContentUnit) error {
	return o.SetContentUnit(boil.GetDB(), insert, related)
}
func (o *File) SetContentUnitP(exec boil.Executor, insert bool, related *ContentUnit) {
	if err := o.SetContentUnit(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *File) SetContentUnitGP(insert bool, related *ContentUnit) {
	if err := o.SetContentUnit(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *File) SetContentUnit(exec boil.Executor, insert bool, related *ContentUnit) error {
	var err error
	if insert {
		if err = related.Insert(exec); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}
	updateQuery := fmt.Sprintf(
		"UPDATE \"files\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"content_unit_id"}),
		strmangle.WhereClause("\"", "\"", 2, filePrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.ID}
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, updateQuery)
		fmt.Fprintln(boil.DebugWriter, values)
	}
	if _, err = exec.Exec(updateQuery, values...); err != nil {
		return errors.Wrap(err, "failed to update local table")
	}
	o.ContentUnitID.Int64 = related.ID
	o.ContentUnitID.Valid = true
	if o.R == nil {
		o.R = &fileR{
			ContentUnit: related,
		}
	} else {
		o.R.ContentUnit = related
	}
	if related.R == nil {
		related.R = &contentUnitR{
			Files: FileSlice{o},
		}
	} else {
		related.R.Files = append(related.R.Files, o)
	}
	return nil
}
func (o *File) RemoveContentUnitG(related *ContentUnit) error {
	return o.RemoveContentUnit(boil.GetDB(), related)
}
func (o *File) RemoveContentUnitP(exec boil.Executor, related *ContentUnit) {
	if err := o.RemoveContentUnit(exec, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *File) RemoveContentUnitGP(related *ContentUnit) {
	if err := o.RemoveContentUnit(boil.GetDB(), related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *File) RemoveContentUnit(exec boil.Executor, related *ContentUnit) error {
	var err error
	o.ContentUnitID.Valid = false
	if err = o.Update(exec, "content_unit_id"); err != nil {
		o.ContentUnitID.Valid = true
		return errors.Wrap(err, "failed to update local table")
	}
	o.R.ContentUnit = nil
	if related == nil || related.R == nil {
		return nil
	}
	for i, ri := range related.R.Files {
		if o.ContentUnitID.Int64 != ri.ContentUnitID.Int64 {
			continue
		}
		ln := len(related.R.Files)
		if ln > 1 && i < ln-1 {
			related.R.Files[i] = related.R.Files[ln-1]
		}
		related.R.Files = related.R.Files[:ln-1]
		break
	}
	return nil
}
func (o *File) SetParentG(insert bool, related *File) error {
	return o.SetParent(boil.GetDB(), insert, related)
}
func (o *File) SetParentP(exec boil.Executor, insert bool, related *File) {
	if err := o.SetParent(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}