func (o *ContentUnitDerivation) SetSourceG(insert bool, related *ContentUnit) error {
	return o.SetSource(boil.GetDB(), insert, related)
}
SetSourceG of the content_unit_derivation to the related item.
Sets o.R.Source to related.
Adds o to related.R.SourceContentUnitDerivations.
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 ContentUnitDerivation struct {
	SourceID  int64  `boil:"source_id" json:"source_id" toml:"source_id" yaml:"source_id"`
	DerivedID int64  `boil:"derived_id" json:"derived_id" toml:"derived_id" yaml:"derived_id"`
	Name      string `boil:"name" json:"name" toml:"name" yaml:"name"`
	R *contentUnitDerivationR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L contentUnitDerivationL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var ContentUnitDerivationColumns = struct {
	SourceID  string
	DerivedID string
	Name      string
}{
	SourceID:  "source_id",
	DerivedID: "derived_id",
	Name:      "name",
}
type contentUnitDerivationR struct {
	Derived *ContentUnit
	Source  *ContentUnit
}
type contentUnitDerivationL struct{}
var (
	contentUnitDerivationColumns               = []string{"source_id", "derived_id", "name"}
	contentUnitDerivationColumnsWithoutDefault = []string{"source_id", "derived_id", "name"}
	contentUnitDerivationColumnsWithDefault    = []string{}
	contentUnitDerivationPrimaryKeyColumns     = []string{"source_id", "derived_id"}
)
type (
	ContentUnitDerivationSlice []*ContentUnitDerivation
	contentUnitDerivationQuery struct {
		*queries.Query
	}
)
var (
	contentUnitDerivationType                 = reflect.TypeOf(&ContentUnitDerivation{})
	contentUnitDerivationMapping              = queries.MakeStructMapping(contentUnitDerivationType)
	contentUnitDerivationPrimaryKeyMapping, _ = queries.BindMapping(contentUnitDerivationType, contentUnitDerivationMapping, contentUnitDerivationPrimaryKeyColumns)
	contentUnitDerivationInsertCacheMut       sync.RWMutex
	contentUnitDerivationInsertCache          = make(map[string]insertCache)
	contentUnitDerivationUpdateCacheMut       sync.RWMutex
	contentUnitDerivationUpdateCache          = make(map[string]updateCache)
	contentUnitDerivationUpsertCacheMut       sync.RWMutex
	contentUnitDerivationUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q contentUnitDerivationQuery) OneP() *ContentUnitDerivation {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q contentUnitDerivationQuery) One() (*ContentUnitDerivation, error) {
	o := &ContentUnitDerivation{}
	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 content_unit_derivations")
	}
	return o, nil
}
func (q contentUnitDerivationQuery) AllP() ContentUnitDerivationSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q contentUnitDerivationQuery) All() (ContentUnitDerivationSlice, error) {
	var o []*ContentUnitDerivation
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to ContentUnitDerivation slice")
	}
	return o, nil
}
func (q contentUnitDerivationQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q contentUnitDerivationQuery) 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 content_unit_derivations rows")
	}
	return count, nil
}
func (q contentUnitDerivationQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q contentUnitDerivationQuery) 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 content_unit_derivations exists")
	}
	return count > 0, nil
}
func (o *ContentUnitDerivation) DerivedG(mods ...qm.QueryMod) contentUnitQuery {
	return o.Derived(boil.GetDB(), mods...)
}
func (o *ContentUnitDerivation) Derived(exec boil.Executor, mods ...qm.QueryMod) contentUnitQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.DerivedID),
	}
	queryMods = append(queryMods, mods...)
	query := ContentUnits(exec, queryMods...)
	queries.SetFrom(query.Query, "\"content_units\"")
	return query
}
func (o *ContentUnitDerivation) SourceG(mods ...qm.QueryMod) contentUnitQuery {
	return o.Source(boil.GetDB(), mods...)
}
func (o *ContentUnitDerivation) Source(exec boil.Executor, mods ...qm.QueryMod) contentUnitQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.SourceID),
	}
	queryMods = append(queryMods, mods...)
	query := ContentUnits(exec, queryMods...)
	queries.SetFrom(query.Query, "\"content_units\"")
	return query
}  
func (contentUnitDerivationL) LoadDerived(e boil.Executor, singular bool, maybeContentUnitDerivation interface{}) error {
	var slice []*ContentUnitDerivation
	var object *ContentUnitDerivation
	count := 1
	if singular {
		object = maybeContentUnitDerivation.(*ContentUnitDerivation)
	} else {
		slice = *maybeContentUnitDerivation.(*[]*ContentUnitDerivation)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &contentUnitDerivationR{}
		}
		args[0] = object.DerivedID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &contentUnitDerivationR{}
			}
			args[i] = obj.DerivedID
		}
	}
	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.Derived = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.DerivedID == foreign.ID {
				local.R.Derived = foreign
				break
			}
		}
	}
	return nil
}
func (contentUnitDerivationL) LoadSource(e boil.Executor, singular bool, maybeContentUnitDerivation interface{}) error {
	var slice []*ContentUnitDerivation
	var object *ContentUnitDerivation
	count := 1
	if singular {
		object = maybeContentUnitDerivation.(*ContentUnitDerivation)
	} else {
		slice = *maybeContentUnitDerivation.(*[]*ContentUnitDerivation)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &contentUnitDerivationR{}
		}
		args[0] = object.SourceID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &contentUnitDerivationR{}
			}
			args[i] = obj.SourceID
		}
	}
	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.Source = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.SourceID == foreign.ID {
				local.R.Source = foreign
				break
			}
		}
	}
	return nil
}
func (o *ContentUnitDerivation) SetDerivedG(insert bool, related *ContentUnit) error {
	return o.SetDerived(boil.GetDB(), insert, related)
}
func (o *ContentUnitDerivation) SetDerivedP(exec boil.Executor, insert bool, related *ContentUnit) {
	if err := o.SetDerived(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentUnitDerivation) SetDerivedGP(insert bool, related *ContentUnit) {
	if err := o.SetDerived(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentUnitDerivation) SetDerived(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 \"content_unit_derivations\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"derived_id"}),
		strmangle.WhereClause("\"", "\"", 2, contentUnitDerivationPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.SourceID, o.DerivedID}
	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.DerivedID = related.ID
	if o.R == nil {
		o.R = &contentUnitDerivationR{
			Derived: related,
		}
	} else {
		o.R.Derived = related
	}
	if related.R == nil {
		related.R = &contentUnitR{
			DerivedContentUnitDerivations: ContentUnitDerivationSlice{o},
		}
	} else {
		related.R.DerivedContentUnitDerivations = append(related.R.DerivedContentUnitDerivations, o)
	}
	return nil
}