func (o *Source) RemoveParent(exec boil.Executor, related *Source) 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.ParentSources {
		if o.ParentID.Int64 != ri.ParentID.Int64 {
			continue
		}
		ln := len(related.R.ParentSources)
		if ln > 1 && i < ln-1 {
			related.R.ParentSources[i] = related.R.ParentSources[ln-1]
		}
		related.R.ParentSources = related.R.ParentSources[:ln-1]
		break
	}
	return nil
}
RemoveParent relationship.
Sets o.R.Parent to nil.
Removes o from all passed in related items' relationships struct (Optional).
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 Source struct {
	ID          int64       `boil:"id" json:"id" toml:"id" yaml:"id"`
	UID         string      `boil:"uid" json:"uid" toml:"uid" yaml:"uid"`
	ParentID    null.Int64  `boil:"parent_id" json:"parent_id,omitempty" toml:"parent_id" yaml:"parent_id,omitempty"`
	Pattern     null.String `boil:"pattern" json:"pattern,omitempty" toml:"pattern" yaml:"pattern,omitempty"`
	TypeID      int64       `boil:"type_id" json:"type_id" toml:"type_id" yaml:"type_id"`
	Position    null.Int    `boil:"position" json:"position,omitempty" toml:"position" yaml:"position,omitempty"`
	Name        string      `boil:"name" json:"name" toml:"name" yaml:"name"`
	Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
	CreatedAt   time.Time   `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	Properties  null.JSON   `boil:"properties" json:"properties,omitempty" toml:"properties" yaml:"properties,omitempty"`
	R *sourceR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L sourceL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var SourceColumns = struct {
	ID          string
	UID         string
	ParentID    string
	Pattern     string
	TypeID      string
	Position    string
	Name        string
	Description string
	CreatedAt   string
	Properties  string
}{
	ID:          "id",
	UID:         "uid",
	ParentID:    "parent_id",
	Pattern:     "pattern",
	TypeID:      "type_id",
	Position:    "position",
	Name:        "name",
	Description: "description",
	CreatedAt:   "created_at",
	Properties:  "properties",
}
type sourceR struct {
	Parent        *Source
	Type          *SourceType
	Authors       AuthorSlice
	ContentUnits  ContentUnitSlice
	SourceI18ns   SourceI18nSlice
	ParentSources SourceSlice
}
type sourceL struct{}
var (
	sourceColumns               = []string{"id", "uid", "parent_id", "pattern", "type_id", "position", "name", "description", "created_at", "properties"}
	sourceColumnsWithoutDefault = []string{"uid", "parent_id", "pattern", "type_id", "position", "name", "description", "properties"}
	sourceColumnsWithDefault    = []string{"id", "created_at"}
	sourcePrimaryKeyColumns     = []string{"id"}
)
type (
	SourceSlice []*Source
	sourceQuery struct {
		*queries.Query
	}
)
var (
	sourceType                 = reflect.TypeOf(&Source{})
	sourceMapping              = queries.MakeStructMapping(sourceType)
	sourcePrimaryKeyMapping, _ = queries.BindMapping(sourceType, sourceMapping, sourcePrimaryKeyColumns)
	sourceInsertCacheMut       sync.RWMutex
	sourceInsertCache          = make(map[string]insertCache)
	sourceUpdateCacheMut       sync.RWMutex
	sourceUpdateCache          = make(map[string]updateCache)
	sourceUpsertCacheMut       sync.RWMutex
	sourceUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q sourceQuery) OneP() *Source {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q sourceQuery) One() (*Source, error) {
	o := &Source{}
	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 sources")
	}
	return o, nil
}
func (q sourceQuery) AllP() SourceSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q sourceQuery) All() (SourceSlice, error) {
	var o []*Source
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to Source slice")
	}
	return o, nil
}
func (q sourceQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q sourceQuery) 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 sources rows")
	}
	return count, nil
}
func (q sourceQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q sourceQuery) 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 sources exists")
	}
	return count > 0, nil
}
func (o *Source) ParentG(mods ...qm.QueryMod) sourceQuery {
	return o.Parent(boil.GetDB(), mods...)
}
func (o *Source) Parent(exec boil.Executor, mods ...qm.QueryMod) sourceQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.ParentID),
	}
	queryMods = append(queryMods, mods...)
	query := Sources(exec, queryMods...)
	queries.SetFrom(query.Query, "\"sources\"")
	return query
}
func (o *Source) TypeG(mods ...qm.QueryMod) sourceTypeQuery {
	return o.Type(boil.GetDB(), mods...)
}
func (o *Source) Type(exec boil.Executor, mods ...qm.QueryMod) sourceTypeQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.TypeID),
	}
	queryMods = append(queryMods, mods...)
	query := SourceTypes(exec, queryMods...)
	queries.SetFrom(query.Query, "\"source_types\"")
	return query
}
func (o *Source) AuthorsG(mods ...qm.QueryMod) authorQuery {
	return o.Authors(boil.GetDB(), mods...)
}
func (o *Source) Authors(exec boil.Executor, mods ...qm.QueryMod) authorQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.InnerJoin("\"authors_sources\" on \"authors\".\"id\" = \"authors_sources\".\"author_id\""),
		qm.Where("\"authors_sources\".\"source_id\"=?", o.ID),
	)
	query := Authors(exec, queryMods...)
	queries.SetFrom(query.Query, "\"authors\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"authors\".*"})
	}
	return query
}
func (o *Source) ContentUnitsG(mods ...qm.QueryMod) contentUnitQuery {
	return o.ContentUnits(boil.GetDB(), mods...)
}
func (o *Source) 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_sources\" on \"content_units\".\"id\" = \"content_units_sources\".\"content_unit_id\""),
		qm.Where("\"content_units_sources\".\"source_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 *Source) SourceI18nsG(mods ...qm.QueryMod) sourceI18nQuery {
	return o.SourceI18ns(boil.GetDB(), mods...)
}
func (o *Source) SourceI18ns(exec boil.Executor, mods ...qm.QueryMod) sourceI18nQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"source_i18n\".\"source_id\"=?", o.ID),
	)
	query := SourceI18ns(exec, queryMods...)
	queries.SetFrom(query.Query, "\"source_i18n\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"source_i18n\".*"})
	}
	return query
}
func (o *Source) ParentSourcesG(mods ...qm.QueryMod) sourceQuery {
	return o.ParentSources(boil.GetDB(), mods...)
}
func (o *Source) ParentSources(exec boil.Executor, mods ...qm.QueryMod) sourceQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"sources\".\"parent_id\"=?", o.ID),
	)
	query := Sources(exec, queryMods...)
	queries.SetFrom(query.Query, "\"sources\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"sources\".*"})
	}
	return query
}
func (sourceL) LoadParent(e boil.Executor, singular bool, maybeSource interface{}) error {
	var slice []*Source
	var object *Source
	count := 1
	if singular {
		object = maybeSource.(*Source)
	} else {
		slice = *maybeSource.(*[]*Source)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &sourceR{}
		}
		args[0] = object.ParentID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &sourceR{}
			}
			args[i] = obj.ParentID
		}
	}
	query := fmt.Sprintf(
		"select * from \"sources\" 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 Source")
	}
	defer results.Close()
	var resultSlice []*Source
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice Source")
	}
	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 (sourceL) LoadType(e boil.Executor, singular bool, maybeSource interface{}) error {
	var slice []*Source
	var object *Source
	count := 1
	if singular {
		object = maybeSource.(*Source)
	} else {
		slice = *maybeSource.(*[]*Source)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &sourceR{}
		}
		args[0] = object.TypeID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &sourceR{}
			}
			args[i] = obj.TypeID
		}
	}
	query := fmt.Sprintf(
		"select * from \"source_types\" 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 SourceType")
	}
	defer results.Close()
	var resultSlice []*SourceType
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice SourceType")
	}
	if len(resultSlice) == 0 {
		return nil
	}
	if singular {
		object.R.Type = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.TypeID == foreign.ID {
				local.R.Type = foreign
				break
			}
		}
	}
	return nil
}
func (sourceL) LoadAuthors(e boil.Executor, singular bool, maybeSource interface{}) error {
	var slice []*Source
	var object *Source
	count := 1
	if singular {
		object = maybeSource.(*Source)
	} else {
		slice = *maybeSource.(*[]*Source)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &sourceR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &sourceR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select \"a\".*, \"b\".\"source_id\" from \"authors\" as \"a\" inner join \"authors_sources\" as \"b\" on \"a\".\"id\" = \"b\".\"author_id\" where \"b\".\"source_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 authors")
	}
	defer results.Close()
	var resultSlice []*Author
	var localJoinCols []int64
	for results.Next() {
		one := new(Author)
		var localJoinCol int64
		err = results.Scan(&one.ID, &one.Code, &one.Name, &one.FullName, &one.CreatedAt, &localJoinCol)
		if err = results.Err(); err != nil {
			return errors.Wrap(err, "failed to plebian-bind eager loaded slice authors")
		}
		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 authors")
	}
	if singular {
		object.R.Authors = resultSlice
		return nil
	}
	for i, foreign := range resultSlice {
		localJoinCol := localJoinCols[i]
		for _, local := range slice {
			if local.ID == localJoinCol {
				local.R.Authors = append(local.R.Authors, foreign)
				break
			}
		}
	}
	return nil
}
func (sourceL) LoadContentUnits(e boil.Executor, singular bool, maybeSource interface{}) error {
	var slice []*Source
	var object *Source
	count := 1
	if singular {
		object = maybeSource.(*Source)
	} else {
		slice = *maybeSource.(*[]*Source)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &sourceR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &sourceR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select \"a\".*, \"b\".\"source_id\" from \"content_units\" as \"a\" inner join \"content_units_sources\" as \"b\" on \"a\".\"id\" = \"b\".\"content_unit_id\" where \"b\".\"source_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 (sourceL) LoadSourceI18ns(e boil.Executor, singular bool, maybeSource interface{}) error {
	var slice []*Source
	var object *Source
	count := 1
	if singular {
		object = maybeSource.(*Source)
	} else {
		slice = *maybeSource.(*[]*Source)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &sourceR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &sourceR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"source_i18n\" where \"source_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 source_i18n")
	}
	defer results.Close()
	var resultSlice []*SourceI18n
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice source_i18n")
	}
	if singular {
		object.R.SourceI18ns = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.SourceID {
				local.R.SourceI18ns = append(local.R.SourceI18ns, foreign)
				break
			}
		}
	}
	return nil
}
func (sourceL) LoadParentSources(e boil.Executor, singular bool, maybeSource interface{}) error {
	var slice []*Source
	var object *Source
	count := 1
	if singular {
		object = maybeSource.(*Source)
	} else {
		slice = *maybeSource.(*[]*Source)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &sourceR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &sourceR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"sources\" 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 sources")
	}
	defer results.Close()
	var resultSlice []*Source
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice sources")
	}
	if singular {
		object.R.ParentSources = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.ParentID.Int64 {
				local.R.ParentSources = append(local.R.ParentSources, foreign)
				break
			}
		}
	}
	return nil
}
func (o *Source) SetParentG(insert bool, related *Source) error {
	return o.SetParent(boil.GetDB(), insert, related)
}
func (o *Source) SetParentP(exec boil.Executor, insert bool, related *Source) {
	if err := o.SetParent(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Source) SetParentGP(insert bool, related *Source) {
	if err := o.SetParent(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Source) SetParent(exec boil.Executor, insert bool, related *Source) 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 \"sources\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"parent_id"}),
		strmangle.WhereClause("\"", "\"", 2, sourcePrimaryKeyColumns),
	)
	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 = &sourceR{
			Parent: related,
		}
	} else {
		o.R.Parent = related
	}
	if related.R == nil {
		related.R = &sourceR{
			ParentSources: SourceSlice{o},
		}
	} else {
		related.R.ParentSources = append(related.R.ParentSources, o)
	}
	return nil
}
func (o *Source) RemoveParentG(related *Source) error {
	return o.RemoveParent(boil.GetDB(), related)
}
func (o *Source) RemoveParentP(exec boil.Executor, related *Source) {
	if err := o.RemoveParent(exec, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Source) RemoveParentGP(related *Source) {
	if err := o.RemoveParent(boil.GetDB(), related); err != nil {
		panic(boil.WrapErr(err))
	}
}