func (o *Publisher) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
InsertP a single record using an executor, and panics on error. See Insert
for whitelist behavior description.
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 Publisher struct {
	ID      int64       `boil:"id" json:"id" toml:"id" yaml:"id"`
	UID     string      `boil:"uid" json:"uid" toml:"uid" yaml:"uid"`
	Pattern null.String `boil:"pattern" json:"pattern,omitempty" toml:"pattern" yaml:"pattern,omitempty"`
	R *publisherR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L publisherL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var PublisherColumns = struct {
	ID      string
	UID     string
	Pattern string
}{
	ID:      "id",
	UID:     "uid",
	Pattern: "pattern",
}
type publisherR struct {
	ContentUnits   ContentUnitSlice
	PublisherI18ns PublisherI18nSlice
}
type publisherL struct{}
var (
	publisherColumns               = []string{"id", "uid", "pattern"}
	publisherColumnsWithoutDefault = []string{"uid", "pattern"}
	publisherColumnsWithDefault    = []string{"id"}
	publisherPrimaryKeyColumns     = []string{"id"}
)
type (
	PublisherSlice []*Publisher
	publisherQuery struct {
		*queries.Query
	}
)
var (
	publisherType                 = reflect.TypeOf(&Publisher{})
	publisherMapping              = queries.MakeStructMapping(publisherType)
	publisherPrimaryKeyMapping, _ = queries.BindMapping(publisherType, publisherMapping, publisherPrimaryKeyColumns)
	publisherInsertCacheMut       sync.RWMutex
	publisherInsertCache          = make(map[string]insertCache)
	publisherUpdateCacheMut       sync.RWMutex
	publisherUpdateCache          = make(map[string]updateCache)
	publisherUpsertCacheMut       sync.RWMutex
	publisherUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q publisherQuery) OneP() *Publisher {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q publisherQuery) One() (*Publisher, error) {
	o := &Publisher{}
	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 publishers")
	}
	return o, nil
}
func (q publisherQuery) AllP() PublisherSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q publisherQuery) All() (PublisherSlice, error) {
	var o []*Publisher
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to Publisher slice")
	}
	return o, nil
}
func (q publisherQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q publisherQuery) 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 publishers rows")
	}
	return count, nil
}
func (q publisherQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q publisherQuery) 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 publishers exists")
	}
	return count > 0, nil
}
func (o *Publisher) ContentUnitsG(mods ...qm.QueryMod) contentUnitQuery {
	return o.ContentUnits(boil.GetDB(), mods...)
}
func (o *Publisher) 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_publishers\" on \"content_units\".\"id\" = \"content_units_publishers\".\"content_unit_id\""),
		qm.Where("\"content_units_publishers\".\"publisher_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 *Publisher) PublisherI18nsG(mods ...qm.QueryMod) publisherI18nQuery {
	return o.PublisherI18ns(boil.GetDB(), mods...)
}
func (o *Publisher) PublisherI18ns(exec boil.Executor, mods ...qm.QueryMod) publisherI18nQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"publisher_i18n\".\"publisher_id\"=?", o.ID),
	)
	query := PublisherI18ns(exec, queryMods...)
	queries.SetFrom(query.Query, "\"publisher_i18n\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"publisher_i18n\".*"})
	}
	return query
}
func (publisherL) LoadContentUnits(e boil.Executor, singular bool, maybePublisher interface{}) error {
	var slice []*Publisher
	var object *Publisher
	count := 1
	if singular {
		object = maybePublisher.(*Publisher)
	} else {
		slice = *maybePublisher.(*[]*Publisher)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &publisherR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &publisherR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select \"a\".*, \"b\".\"publisher_id\" from \"content_units\" as \"a\" inner join \"content_units_publishers\" as \"b\" on \"a\".\"id\" = \"b\".\"content_unit_id\" where \"b\".\"publisher_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 (publisherL) LoadPublisherI18ns(e boil.Executor, singular bool, maybePublisher interface{}) error {
	var slice []*Publisher
	var object *Publisher
	count := 1
	if singular {
		object = maybePublisher.(*Publisher)
	} else {
		slice = *maybePublisher.(*[]*Publisher)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &publisherR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &publisherR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"publisher_i18n\" where \"publisher_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 publisher_i18n")
	}
	defer results.Close()
	var resultSlice []*PublisherI18n
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice publisher_i18n")
	}
	if singular {
		object.R.PublisherI18ns = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.PublisherID {
				local.R.PublisherI18ns = append(local.R.PublisherI18ns, foreign)
				break
			}
		}
	}
	return nil
}
func (o *Publisher) AddContentUnitsG(insert bool, related ...*ContentUnit) error {
	return o.AddContentUnits(boil.GetDB(), insert, related...)
}
func (o *Publisher) AddContentUnitsP(exec boil.Executor, insert bool, related ...*ContentUnit) {
	if err := o.AddContentUnits(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Publisher) AddContentUnitsGP(insert bool, related ...*ContentUnit) {
	if err := o.AddContentUnits(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Publisher) 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_publishers\" (\"publisher_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 = &publisherR{
			ContentUnits: related,
		}
	} else {
		o.R.ContentUnits = append(o.R.ContentUnits, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &contentUnitR{
				Publishers: PublisherSlice{o},
			}
		} else {
			rel.R.Publishers = append(rel.R.Publishers, o)
		}
	}
	return nil
}
func (o *Publisher) SetContentUnitsG(insert bool, related ...*ContentUnit) error {
	return o.SetContentUnits(boil.GetDB(), insert, related...)
}
func (o *Publisher) SetContentUnitsP(exec boil.Executor, insert bool, related ...*ContentUnit) {
	if err := o.SetContentUnits(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Publisher) SetContentUnitsGP(insert bool, related ...*ContentUnit) {
	if err := o.SetContentUnits(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Publisher) SetContentUnits(exec boil.Executor, insert bool, related ...*ContentUnit) error {
	query := "delete from \"content_units_publishers\" where \"publisher_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")
	}
	removeContentUnitsFromPublishersSlice(o, related)
	if o.R != nil {
		o.R.ContentUnits = nil
	}
	return o.AddContentUnits(exec, insert, related...)
}
func (o *Publisher) RemoveContentUnitsG(related ...*ContentUnit) error {
	return o.RemoveContentUnits(boil.GetDB(), related...)
}
func (o *Publisher) RemoveContentUnitsP(exec boil.Executor, related ...*ContentUnit) {
	if err := o.RemoveContentUnits(exec, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Publisher) RemoveContentUnitsGP(related ...*ContentUnit) {
	if err := o.RemoveContentUnits(boil.GetDB(), related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Publisher) RemoveContentUnits(exec boil.Executor, related ...*ContentUnit) error {
	var err error
	query := fmt.Sprintf(
		"delete from \"content_units_publishers\" where \"publisher_id\" = $1 and \"content_unit_id\" in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, len(related), 2, 1),
	)
	values := []interface{}{o.ID}
	for _, rel := range related {
		values = append(values, 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 remove relationships before set")
	}
	removeContentUnitsFromPublishersSlice(o, related)
	if o.R == nil {
		return nil
	}
	for _, rel := range related {
		for i, ri := range o.R.ContentUnits {
			if rel != ri {
				continue
			}
			ln := len(o.R.ContentUnits)
			if ln > 1 && i < ln-1 {
				o.R.ContentUnits[i] = o.R.ContentUnits[ln-1]
			}
			o.R.ContentUnits = o.R.ContentUnits[:ln-1]
			break
		}
	}
	return nil
}
func removeContentUnitsFromPublishersSlice(o *Publisher, related []*ContentUnit) {
	for _, rel := range related {
		if rel.R == nil {
			continue
		}
		for i, ri := range rel.R.Publishers {
			if o.ID != ri.ID {
				continue
			}
			ln := len(rel.R.Publishers)
			if ln > 1 && i < ln-1 {
				rel.R.Publishers[i] = rel.R.Publishers[ln-1]
			}
			rel.R.Publishers = rel.R.Publishers[:ln-1]
			break
		}
	}
}
func (o *Publisher) AddPublisherI18nsG(insert bool, related ...*PublisherI18n) error {
	return o.AddPublisherI18ns(boil.GetDB(), insert, related...)
}
func (o *Publisher) AddPublisherI18nsP(exec boil.Executor, insert bool, related ...*PublisherI18n) {
	if err := o.AddPublisherI18ns(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Publisher) AddPublisherI18nsGP(insert bool, related ...*PublisherI18n) {
	if err := o.AddPublisherI18ns(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Publisher) AddPublisherI18ns(exec boil.Executor, insert bool, related ...*PublisherI18n) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.PublisherID = o.ID
			if err = rel.Insert(exec); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"publisher_i18n\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"publisher_id"}),
				strmangle.WhereClause("\"", "\"", 2, publisherI18nPrimaryKeyColumns),
			)
			values := []interface{}{o.ID, rel.PublisherID, rel.Language}
			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 foreign table")
			}
			rel.PublisherID = o.ID
		}
	}
	if o.R == nil {
		o.R = &publisherR{
			PublisherI18ns: related,
		}
	} else {
		o.R.PublisherI18ns = append(o.R.PublisherI18ns, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &publisherI18nR{
				Publisher: o,
			}
		} else {
			rel.R.Publisher = o
		}
	}
	return nil
}
func PublishersG(mods ...qm.QueryMod) publisherQuery {
	return Publishers(boil.GetDB(), mods...)
}
func Publishers(exec boil.Executor, mods ...qm.QueryMod) publisherQuery {
	mods = append(mods, qm.From("\"publishers\""))
	return publisherQuery{NewQuery(exec, mods...)}
}
func FindPublisherG(id int64, selectCols ...string) (*Publisher, error) {
	return FindPublisher(boil.GetDB(), id, selectCols...)
}
func FindPublisherGP(id int64, selectCols ...string) *Publisher {
	retobj, err := FindPublisher(boil.GetDB(), id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindPublisher(exec boil.Executor, id int64, selectCols ...string) (*Publisher, error) {
	publisherObj := &Publisher{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"publishers\" where \"id\"=$1", sel,
	)
	q := queries.Raw(exec, query, id)
	err := q.Bind(publisherObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: unable to select from publishers")
	}
	return publisherObj, nil
}
func FindPublisherP(exec boil.Executor, id int64, selectCols ...string) *Publisher {
	retobj, err := FindPublisher(exec, id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func (o *Publisher) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
func (o *Publisher) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}