func (o *Tag) RemoveContentUnitsP(exec boil.Executor, related ...*ContentUnit) {
	if err := o.RemoveContentUnits(exec, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
RemoveContentUnitsP relationships from objects passed in.
Removes related items from R.ContentUnits (uses pointer comparison, removal does not keep order)
Sets related.R.Tags.
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 Tag struct {
	ID          int64       `boil:"id" json:"id" toml:"id" yaml:"id"`
	Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
	ParentID    null.Int64  `boil:"parent_id" json:"parent_id,omitempty" toml:"parent_id" yaml:"parent_id,omitempty"`
	UID         string      `boil:"uid" json:"uid" toml:"uid" yaml:"uid"`
	Pattern     null.String `boil:"pattern" json:"pattern,omitempty" toml:"pattern" yaml:"pattern,omitempty"`
	R *tagR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L tagL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var TagColumns = struct {
	ID          string
	Description string
	ParentID    string
	UID         string
	Pattern     string
}{
	ID:          "id",
	Description: "description",
	ParentID:    "parent_id",
	UID:         "uid",
	Pattern:     "pattern",
}
type tagR struct {
	Parent       *Tag
	ContentUnits ContentUnitSlice
	TagI18ns     TagI18nSlice
	ParentTags   TagSlice
}
type tagL struct{}
var (
	tagColumns               = []string{"id", "description", "parent_id", "uid", "pattern"}
	tagColumnsWithoutDefault = []string{"description", "parent_id", "uid", "pattern"}
	tagColumnsWithDefault    = []string{"id"}
	tagPrimaryKeyColumns     = []string{"id"}
)
type (
	TagSlice []*Tag
	tagQuery struct {
		*queries.Query
	}
)
var (
	tagType                 = reflect.TypeOf(&Tag{})
	tagMapping              = queries.MakeStructMapping(tagType)
	tagPrimaryKeyMapping, _ = queries.BindMapping(tagType, tagMapping, tagPrimaryKeyColumns)
	tagInsertCacheMut       sync.RWMutex
	tagInsertCache          = make(map[string]insertCache)
	tagUpdateCacheMut       sync.RWMutex
	tagUpdateCache          = make(map[string]updateCache)
	tagUpsertCacheMut       sync.RWMutex
	tagUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q tagQuery) OneP() *Tag {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q tagQuery) One() (*Tag, error) {
	o := &Tag{}
	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 tags")
	}
	return o, nil
}
func (q tagQuery) AllP() TagSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q tagQuery) All() (TagSlice, error) {
	var o []*Tag
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to Tag slice")
	}
	return o, nil
}
func (q tagQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q tagQuery) 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 tags rows")
	}
	return count, nil
}
func (q tagQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q tagQuery) 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 tags exists")
	}
	return count > 0, nil
}
func (o *Tag) ParentG(mods ...qm.QueryMod) tagQuery {
	return o.Parent(boil.GetDB(), mods...)
}
func (o *Tag) Parent(exec boil.Executor, mods ...qm.QueryMod) tagQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.ParentID),
	}
	queryMods = append(queryMods, mods...)
	query := Tags(exec, queryMods...)
	queries.SetFrom(query.Query, "\"tags\"")
	return query
}
func (o *Tag) ContentUnitsG(mods ...qm.QueryMod) contentUnitQuery {
	return o.ContentUnits(boil.GetDB(), mods...)
}
func (o *Tag) ContentUnits(exec boil.Executor, mods ...qm.QueryMod) contentUnitQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.InnerJoin("\"content_units_tags\" on \"content_units\".\"id\" = \"content_units_tags\".\"content_unit_id\""),
		qm.Where("\"content_units_tags\".\"tag_id\"=?", o.ID),
	)
	query := ContentUnits(exec, queryMods...)
	queries.SetFrom(query.Query, "\"content_units\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"content_units\".*"})
	}
	return query
}
func (o *Tag) TagI18nsG(mods ...qm.QueryMod) tagI18nQuery {
	return o.TagI18ns(boil.GetDB(), mods...)
}
func (o *Tag) TagI18ns(exec boil.Executor, mods ...qm.QueryMod) tagI18nQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"tag_i18n\".\"tag_id\"=?", o.ID),
	)
	query := TagI18ns(exec, queryMods...)
	queries.SetFrom(query.Query, "\"tag_i18n\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"tag_i18n\".*"})
	}
	return query
}
func (o *Tag) ParentTagsG(mods ...qm.QueryMod) tagQuery {
	return o.ParentTags(boil.GetDB(), mods...)
}
func (o *Tag) ParentTags(exec boil.Executor, mods ...qm.QueryMod) tagQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"tags\".\"parent_id\"=?", o.ID),
	)
	query := Tags(exec, queryMods...)
	queries.SetFrom(query.Query, "\"tags\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"tags\".*"})
	}
	return query
}
func (tagL) LoadParent(e boil.Executor, singular bool, maybeTag interface{}) error {
	var slice []*Tag
	var object *Tag
	count := 1
	if singular {
		object = maybeTag.(*Tag)
	} else {
		slice = *maybeTag.(*[]*Tag)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &tagR{}
		}
		args[0] = object.ParentID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &tagR{}
			}
			args[i] = obj.ParentID
		}
	}
	query := fmt.Sprintf(
		"select * from \"tags\" 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 Tag")
	}
	defer results.Close()
	var resultSlice []*Tag
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice Tag")
	}
	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 (tagL) LoadContentUnits(e boil.Executor, singular bool, maybeTag interface{}) error {
	var slice []*Tag
	var object *Tag
	count := 1
	if singular {
		object = maybeTag.(*Tag)
	} else {
		slice = *maybeTag.(*[]*Tag)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &tagR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &tagR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select \"a\".*, \"b\".\"tag_id\" from \"content_units\" as \"a\" inner join \"content_units_tags\" as \"b\" on \"a\".\"id\" = \"b\".\"content_unit_id\" where \"b\".\"tag_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 content_units")
	}
	defer results.Close()
	var resultSlice []*ContentUnit
	var localJoinCols []int64
	for results.Next() {
		one := new(ContentUnit)
		var localJoinCol int64
		err = results.Scan(&one.ID, &one.UID, &one.TypeID, &one.CreatedAt, &one.Properties, &one.Secure, &one.Published, &localJoinCol)
		if err = results.Err(); err != nil {
			return errors.Wrap(err, "failed to plebian-bind eager loaded slice content_units")
		}
		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 content_units")
	}
	if singular {
		object.R.ContentUnits = resultSlice
		return nil
	}
	for i, foreign := range resultSlice {
		localJoinCol := localJoinCols[i]
		for _, local := range slice {
			if local.ID == localJoinCol {
				local.R.ContentUnits = append(local.R.ContentUnits, foreign)
				break
			}
		}
	}
	return nil
}
func (tagL) LoadTagI18ns(e boil.Executor, singular bool, maybeTag interface{}) error {
	var slice []*Tag
	var object *Tag
	count := 1
	if singular {
		object = maybeTag.(*Tag)
	} else {
		slice = *maybeTag.(*[]*Tag)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &tagR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &tagR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"tag_i18n\" where \"tag_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 tag_i18n")
	}
	defer results.Close()
	var resultSlice []*TagI18n
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice tag_i18n")
	}
	if singular {
		object.R.TagI18ns = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.TagID {
				local.R.TagI18ns = append(local.R.TagI18ns, foreign)
				break
			}
		}
	}
	return nil
}
func (tagL) LoadParentTags(e boil.Executor, singular bool, maybeTag interface{}) error {
	var slice []*Tag
	var object *Tag
	count := 1
	if singular {
		object = maybeTag.(*Tag)
	} else {
		slice = *maybeTag.(*[]*Tag)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &tagR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &tagR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"tags\" 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 tags")
	}
	defer results.Close()
	var resultSlice []*Tag
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice tags")
	}
	if singular {
		object.R.ParentTags = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.ParentID.Int64 {
				local.R.ParentTags = append(local.R.ParentTags, foreign)
				break
			}
		}
	}
	return nil
}
func (o *Tag) SetParentG(insert bool, related *Tag) error {
	return o.SetParent(boil.GetDB(), insert, related)
}
func (o *Tag) SetParentP(exec boil.Executor, insert bool, related *Tag) {
	if err := o.SetParent(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Tag) SetParentGP(insert bool, related *Tag) {
	if err := o.SetParent(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Tag) SetParent(exec boil.Executor, insert bool, related *Tag) 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 \"tags\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"parent_id"}),
		strmangle.WhereClause("\"", "\"", 2, tagPrimaryKeyColumns),
	)
	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.ParentID.Int64 = related.ID
	o.ParentID.Valid = true
	if o.R == nil {
		o.R = &tagR{
			Parent: related,
		}
	} else {
		o.R.Parent = related
	}
	if related.R == nil {
		related.R = &tagR{
			ParentTags: TagSlice{o},
		}
	} else {
		related.R.ParentTags = append(related.R.ParentTags, o)
	}
	return nil
}
func (o *Tag) RemoveParentG(related *Tag) error {
	return o.RemoveParent(boil.GetDB(), related)
}
func (o *Tag) RemoveParentP(exec boil.Executor, related *Tag) {
	if err := o.RemoveParent(exec, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Tag) RemoveParentGP(related *Tag) {
	if err := o.RemoveParent(boil.GetDB(), related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Tag) RemoveParent(exec boil.Executor, related *Tag) error {
	var err error
	o.ParentID.Valid = false
	if err = o.Update(exec, "parent_id"); err != nil {
		o.ParentID.Valid = true
		return errors.Wrap(err, "failed to update local table")
	}
	o.R.Parent = nil
	if related == nil || related.R == nil {
		return nil
	}
	for i, ri := range related.R.ParentTags {
		if o.ParentID.Int64 != ri.ParentID.Int64 {
			continue
		}
		ln := len(related.R.ParentTags)
		if ln > 1 && i < ln-1 {
			related.R.ParentTags[i] = related.R.ParentTags[ln-1]
		}
		related.R.ParentTags = related.R.ParentTags[:ln-1]
		break
	}
	return nil
}
func (o *Tag) AddContentUnitsG(insert bool, related ...*ContentUnit) error {
	return o.AddContentUnits(boil.GetDB(), insert, related...)
}
func (o *Tag) AddContentUnitsP(exec boil.Executor, insert bool, related ...*ContentUnit) {
	if err := o.AddContentUnits(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Tag) AddContentUnitsGP(insert bool, related ...*ContentUnit) {
	if err := o.AddContentUnits(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Tag) AddContentUnits(exec boil.Executor, insert bool, related ...*ContentUnit) 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 \"content_units_tags\" (\"tag_id\", \"content_unit_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 = &tagR{
			ContentUnits: related,
		}
	} else {
		o.R.ContentUnits = append(o.R.ContentUnits, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &contentUnitR{
				Tags: TagSlice{o},
			}
		} else {
			rel.R.Tags = append(rel.R.Tags, o)
		}
	}
	return nil
}
func (o *Tag) SetContentUnitsG(insert bool, related ...*ContentUnit) error {
	return o.SetContentUnits(boil.GetDB(), insert, related...)
}
func (o *Tag) SetContentUnitsP(exec boil.Executor, insert bool, related ...*ContentUnit) {
	if err := o.SetContentUnits(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Tag) SetContentUnitsGP(insert bool, related ...*ContentUnit) {
	if err := o.SetContentUnits(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Tag) SetContentUnits(exec boil.Executor, insert bool, related ...*ContentUnit) error {
	query := "delete from \"content_units_tags\" where \"tag_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")
	}
	removeContentUnitsFromTagsSlice(o, related)
	if o.R != nil {
		o.R.ContentUnits = nil
	}
	return o.AddContentUnits(exec, insert, related...)
}
func (o *Tag) RemoveContentUnitsG(related ...*ContentUnit) error {
	return o.RemoveContentUnits(boil.GetDB(), related...)
}