Bnei-Baruch/mdb

View on GitHub
importer/kmedia/kmodels/containers.go

Summary

Maintainability
F
1 mo
Test Coverage
// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.

package kmodels

import (
    "bytes"
    "database/sql"
    "fmt"
    "reflect"
    "strings"
    "sync"
    "time"

    "github.com/pkg/errors"
    "github.com/volatiletech/sqlboiler/boil"
    "github.com/volatiletech/sqlboiler/queries"
    "github.com/volatiletech/sqlboiler/queries/qm"
    "github.com/volatiletech/sqlboiler/strmangle"
    "gopkg.in/volatiletech/null.v6"
)

// Container is an object representing the database table.
type Container struct {
    ID              int         `boil:"id" json:"id" toml:"id" yaml:"id"`
    Name            null.String `boil:"name" json:"name,omitempty" toml:"name" yaml:"name,omitempty"`
    CreatedAt       null.Time   `boil:"created_at" json:"created_at,omitempty" toml:"created_at" yaml:"created_at,omitempty"`
    UpdatedAt       null.Time   `boil:"updated_at" json:"updated_at,omitempty" toml:"updated_at" yaml:"updated_at,omitempty"`
    Filmdate        null.Time   `boil:"filmdate" json:"filmdate,omitempty" toml:"filmdate" yaml:"filmdate,omitempty"`
    LangID          null.String `boil:"lang_id" json:"lang_id,omitempty" toml:"lang_id" yaml:"lang_id,omitempty"`
    LecturerID      null.Int    `boil:"lecturer_id" json:"lecturer_id,omitempty" toml:"lecturer_id" yaml:"lecturer_id,omitempty"`
    Secure          int         `boil:"secure" json:"secure" toml:"secure" yaml:"secure"`
    ContentTypeID   null.Int    `boil:"content_type_id" json:"content_type_id,omitempty" toml:"content_type_id" yaml:"content_type_id,omitempty"`
    MarkedForMerge  null.Bool   `boil:"marked_for_merge" json:"marked_for_merge,omitempty" toml:"marked_for_merge" yaml:"marked_for_merge,omitempty"`
    SecureChanged   null.Bool   `boil:"secure_changed" json:"secure_changed,omitempty" toml:"secure_changed" yaml:"secure_changed,omitempty"`
    AutoParsed      null.Bool   `boil:"auto_parsed" json:"auto_parsed,omitempty" toml:"auto_parsed" yaml:"auto_parsed,omitempty"`
    VirtualLessonID null.Int    `boil:"virtual_lesson_id" json:"virtual_lesson_id,omitempty" toml:"virtual_lesson_id" yaml:"virtual_lesson_id,omitempty"`
    PlaytimeSecs    null.Int    `boil:"playtime_secs" json:"playtime_secs,omitempty" toml:"playtime_secs" yaml:"playtime_secs,omitempty"`
    UserID          null.Int    `boil:"user_id" json:"user_id,omitempty" toml:"user_id" yaml:"user_id,omitempty"`
    ForCensorship   null.Bool   `boil:"for_censorship" json:"for_censorship,omitempty" toml:"for_censorship" yaml:"for_censorship,omitempty"`
    OpenedByCensor  null.Bool   `boil:"opened_by_censor" json:"opened_by_censor,omitempty" toml:"opened_by_censor" yaml:"opened_by_censor,omitempty"`
    ClosedByCensor  null.Bool   `boil:"closed_by_censor" json:"closed_by_censor,omitempty" toml:"closed_by_censor" yaml:"closed_by_censor,omitempty"`
    CensorID        null.Int    `boil:"censor_id" json:"censor_id,omitempty" toml:"censor_id" yaml:"censor_id,omitempty"`
    Position        null.Int    `boil:"position" json:"position,omitempty" toml:"position" yaml:"position,omitempty"`

    R *containerR `boil:"-" json:"-" toml:"-" yaml:"-"`
    L containerL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

var ContainerColumns = struct {
    ID              string
    Name            string
    CreatedAt       string
    UpdatedAt       string
    Filmdate        string
    LangID          string
    LecturerID      string
    Secure          string
    ContentTypeID   string
    MarkedForMerge  string
    SecureChanged   string
    AutoParsed      string
    VirtualLessonID string
    PlaytimeSecs    string
    UserID          string
    ForCensorship   string
    OpenedByCensor  string
    ClosedByCensor  string
    CensorID        string
    Position        string
}{
    ID:              "id",
    Name:            "name",
    CreatedAt:       "created_at",
    UpdatedAt:       "updated_at",
    Filmdate:        "filmdate",
    LangID:          "lang_id",
    LecturerID:      "lecturer_id",
    Secure:          "secure",
    ContentTypeID:   "content_type_id",
    MarkedForMerge:  "marked_for_merge",
    SecureChanged:   "secure_changed",
    AutoParsed:      "auto_parsed",
    VirtualLessonID: "virtual_lesson_id",
    PlaytimeSecs:    "playtime_secs",
    UserID:          "user_id",
    ForCensorship:   "for_censorship",
    OpenedByCensor:  "opened_by_censor",
    ClosedByCensor:  "closed_by_censor",
    CensorID:        "censor_id",
    Position:        "position",
}

// containerR is where relationships are stored.
type containerR struct {
    ContentType           *ContentType
    Lang                  *Language
    VirtualLesson         *VirtualLesson
    Catalogs              CatalogSlice
    ContainerDescriptions ContainerDescriptionSlice
    FileAssets            FileAssetSlice
    Labels                LabelSlice
}

// containerL is where Load methods for each relationship are stored.
type containerL struct{}

var (
    containerColumns               = []string{"id", "name", "created_at", "updated_at", "filmdate", "lang_id", "lecturer_id", "secure", "content_type_id", "marked_for_merge", "secure_changed", "auto_parsed", "virtual_lesson_id", "playtime_secs", "user_id", "for_censorship", "opened_by_censor", "closed_by_censor", "censor_id", "position"}
    containerColumnsWithoutDefault = []string{"name", "created_at", "updated_at", "filmdate", "lang_id", "lecturer_id", "content_type_id", "marked_for_merge", "virtual_lesson_id", "playtime_secs", "user_id", "censor_id", "position"}
    containerColumnsWithDefault    = []string{"id", "secure", "secure_changed", "auto_parsed", "for_censorship", "opened_by_censor", "closed_by_censor"}
    containerPrimaryKeyColumns     = []string{"id"}
)

type (
    // ContainerSlice is an alias for a slice of pointers to Container.
    // This should generally be used opposed to []Container.
    ContainerSlice []*Container

    containerQuery struct {
        *queries.Query
    }
)

// Cache for insert, update and upsert
var (
    containerType                 = reflect.TypeOf(&Container{})
    containerMapping              = queries.MakeStructMapping(containerType)
    containerPrimaryKeyMapping, _ = queries.BindMapping(containerType, containerMapping, containerPrimaryKeyColumns)
    containerInsertCacheMut       sync.RWMutex
    containerInsertCache          = make(map[string]insertCache)
    containerUpdateCacheMut       sync.RWMutex
    containerUpdateCache          = make(map[string]updateCache)
    containerUpsertCacheMut       sync.RWMutex
    containerUpsertCache          = make(map[string]insertCache)
)

var (
    // Force time package dependency for automated UpdatedAt/CreatedAt.
    _ = time.Second
    // Force bytes in case of primary key column that uses []byte (for relationship compares)
    _ = bytes.MinRead
)

// OneP returns a single container record from the query, and panics on error.
func (q containerQuery) OneP() *Container {
    o, err := q.One()
    if err != nil {
        panic(boil.WrapErr(err))
    }

    return o
}

// One returns a single container record from the query.
func (q containerQuery) One() (*Container, error) {
    o := &Container{}

    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, "kmodels: failed to execute a one query for containers")
    }

    return o, nil
}

// AllP returns all Container records from the query, and panics on error.
func (q containerQuery) AllP() ContainerSlice {
    o, err := q.All()
    if err != nil {
        panic(boil.WrapErr(err))
    }

    return o
}

// All returns all Container records from the query.
func (q containerQuery) All() (ContainerSlice, error) {
    var o []*Container

    err := q.Bind(&o)
    if err != nil {
        return nil, errors.Wrap(err, "kmodels: failed to assign all query results to Container slice")
    }

    return o, nil
}

// CountP returns the count of all Container records in the query, and panics on error.
func (q containerQuery) CountP() int64 {
    c, err := q.Count()
    if err != nil {
        panic(boil.WrapErr(err))
    }

    return c
}

// Count returns the count of all Container records in the query.
func (q containerQuery) 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, "kmodels: failed to count containers rows")
    }

    return count, nil
}

// Exists checks if the row exists in the table, and panics on error.
func (q containerQuery) ExistsP() bool {
    e, err := q.Exists()
    if err != nil {
        panic(boil.WrapErr(err))
    }

    return e
}

// Exists checks if the row exists in the table.
func (q containerQuery) 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, "kmodels: failed to check if containers exists")
    }

    return count > 0, nil
}

// ContentTypeG pointed to by the foreign key.
func (o *Container) ContentTypeG(mods ...qm.QueryMod) contentTypeQuery {
    return o.ContentType(boil.GetDB(), mods...)
}

// ContentType pointed to by the foreign key.
func (o *Container) ContentType(exec boil.Executor, mods ...qm.QueryMod) contentTypeQuery {
    queryMods := []qm.QueryMod{
        qm.Where("id=?", o.ContentTypeID),
    }

    queryMods = append(queryMods, mods...)

    query := ContentTypes(exec, queryMods...)
    queries.SetFrom(query.Query, "\"content_types\"")

    return query
}

// LangG pointed to by the foreign key.
func (o *Container) LangG(mods ...qm.QueryMod) languageQuery {
    return o.Lang(boil.GetDB(), mods...)
}

// Lang pointed to by the foreign key.
func (o *Container) Lang(exec boil.Executor, mods ...qm.QueryMod) languageQuery {
    queryMods := []qm.QueryMod{
        qm.Where("code3=?", o.LangID),
    }

    queryMods = append(queryMods, mods...)

    query := Languages(exec, queryMods...)
    queries.SetFrom(query.Query, "\"languages\"")

    return query
}

// VirtualLessonG pointed to by the foreign key.
func (o *Container) VirtualLessonG(mods ...qm.QueryMod) virtualLessonQuery {
    return o.VirtualLesson(boil.GetDB(), mods...)
}

// VirtualLesson pointed to by the foreign key.
func (o *Container) VirtualLesson(exec boil.Executor, mods ...qm.QueryMod) virtualLessonQuery {
    queryMods := []qm.QueryMod{
        qm.Where("id=?", o.VirtualLessonID),
    }

    queryMods = append(queryMods, mods...)

    query := VirtualLessons(exec, queryMods...)
    queries.SetFrom(query.Query, "\"virtual_lessons\"")

    return query
}

// CatalogsG retrieves all the catalog's catalogs.
func (o *Container) CatalogsG(mods ...qm.QueryMod) catalogQuery {
    return o.Catalogs(boil.GetDB(), mods...)
}

// Catalogs retrieves all the catalog's catalogs with an executor.
func (o *Container) Catalogs(exec boil.Executor, mods ...qm.QueryMod) catalogQuery {
    var queryMods []qm.QueryMod
    if len(mods) != 0 {
        queryMods = append(queryMods, mods...)
    }

    queryMods = append(queryMods,
        qm.InnerJoin("\"catalogs_containers\" on \"catalogs\".\"id\" = \"catalogs_containers\".\"catalog_id\""),
        qm.Where("\"catalogs_containers\".\"container_id\"=?", o.ID),
    )

    query := Catalogs(exec, queryMods...)
    queries.SetFrom(query.Query, "\"catalogs\"")

    if len(queries.GetSelect(query.Query)) == 0 {
        queries.SetSelect(query.Query, []string{"\"catalogs\".*"})
    }

    return query
}

// ContainerDescriptionsG retrieves all the container_description's container descriptions.
func (o *Container) ContainerDescriptionsG(mods ...qm.QueryMod) containerDescriptionQuery {
    return o.ContainerDescriptions(boil.GetDB(), mods...)
}

// ContainerDescriptions retrieves all the container_description's container descriptions with an executor.
func (o *Container) ContainerDescriptions(exec boil.Executor, mods ...qm.QueryMod) containerDescriptionQuery {
    var queryMods []qm.QueryMod
    if len(mods) != 0 {
        queryMods = append(queryMods, mods...)
    }

    queryMods = append(queryMods,
        qm.Where("\"container_descriptions\".\"container_id\"=?", o.ID),
    )

    query := ContainerDescriptions(exec, queryMods...)
    queries.SetFrom(query.Query, "\"container_descriptions\"")

    if len(queries.GetSelect(query.Query)) == 0 {
        queries.SetSelect(query.Query, []string{"\"container_descriptions\".*"})
    }

    return query
}

// FileAssetsG retrieves all the file_asset's file assets.
func (o *Container) FileAssetsG(mods ...qm.QueryMod) fileAssetQuery {
    return o.FileAssets(boil.GetDB(), mods...)
}

// FileAssets retrieves all the file_asset's file assets with an executor.
func (o *Container) FileAssets(exec boil.Executor, mods ...qm.QueryMod) fileAssetQuery {
    var queryMods []qm.QueryMod
    if len(mods) != 0 {
        queryMods = append(queryMods, mods...)
    }

    queryMods = append(queryMods,
        qm.InnerJoin("\"containers_file_assets\" on \"file_assets\".\"id\" = \"containers_file_assets\".\"file_asset_id\""),
        qm.Where("\"containers_file_assets\".\"container_id\"=?", o.ID),
    )

    query := FileAssets(exec, queryMods...)
    queries.SetFrom(query.Query, "\"file_assets\"")

    if len(queries.GetSelect(query.Query)) == 0 {
        queries.SetSelect(query.Query, []string{"\"file_assets\".*"})
    }

    return query
}

// LabelsG retrieves all the label's labels.
func (o *Container) LabelsG(mods ...qm.QueryMod) labelQuery {
    return o.Labels(boil.GetDB(), mods...)
}

// Labels retrieves all the label's labels with an executor.
func (o *Container) Labels(exec boil.Executor, mods ...qm.QueryMod) labelQuery {
    var queryMods []qm.QueryMod
    if len(mods) != 0 {
        queryMods = append(queryMods, mods...)
    }

    queryMods = append(queryMods,
        qm.InnerJoin("\"containers_labels\" on \"labels\".\"id\" = \"containers_labels\".\"label_id\""),
        qm.Where("\"containers_labels\".\"container_id\"=?", o.ID),
    )

    query := Labels(exec, queryMods...)
    queries.SetFrom(query.Query, "\"labels\"")

    if len(queries.GetSelect(query.Query)) == 0 {
        queries.SetSelect(query.Query, []string{"\"labels\".*"})
    }

    return query
}

// LoadContentType allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (containerL) LoadContentType(e boil.Executor, singular bool, maybeContainer interface{}) error {
    var slice []*Container
    var object *Container

    count := 1
    if singular {
        object = maybeContainer.(*Container)
    } else {
        slice = *maybeContainer.(*[]*Container)
        count = len(slice)
    }

    args := make([]interface{}, count)
    if singular {
        if object.R == nil {
            object.R = &containerR{}
        }
        args[0] = object.ContentTypeID
    } else {
        for i, obj := range slice {
            if obj.R == nil {
                obj.R = &containerR{}
            }
            args[i] = obj.ContentTypeID
        }
    }

    query := fmt.Sprintf(
        "select * from \"content_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 ContentType")
    }
    defer results.Close()

    var resultSlice []*ContentType
    if err = queries.Bind(results, &resultSlice); err != nil {
        return errors.Wrap(err, "failed to bind eager loaded slice ContentType")
    }

    if len(resultSlice) == 0 {
        return nil
    }

    if singular {
        object.R.ContentType = resultSlice[0]
        return nil
    }

    for _, local := range slice {
        for _, foreign := range resultSlice {
            if local.ContentTypeID.Int == foreign.ID {
                local.R.ContentType = foreign
                break
            }
        }
    }

    return nil
}

// LoadLang allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (containerL) LoadLang(e boil.Executor, singular bool, maybeContainer interface{}) error {
    var slice []*Container
    var object *Container

    count := 1
    if singular {
        object = maybeContainer.(*Container)
    } else {
        slice = *maybeContainer.(*[]*Container)
        count = len(slice)
    }

    args := make([]interface{}, count)
    if singular {
        if object.R == nil {
            object.R = &containerR{}
        }
        args[0] = object.LangID
    } else {
        for i, obj := range slice {
            if obj.R == nil {
                obj.R = &containerR{}
            }
            args[i] = obj.LangID
        }
    }

    query := fmt.Sprintf(
        "select * from \"languages\" where \"code3\" 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 Language")
    }
    defer results.Close()

    var resultSlice []*Language
    if err = queries.Bind(results, &resultSlice); err != nil {
        return errors.Wrap(err, "failed to bind eager loaded slice Language")
    }

    if len(resultSlice) == 0 {
        return nil
    }

    if singular {
        object.R.Lang = resultSlice[0]
        return nil
    }

    for _, local := range slice {
        for _, foreign := range resultSlice {
            if local.LangID.String == foreign.Code3.String {
                local.R.Lang = foreign
                break
            }
        }
    }

    return nil
}

// LoadVirtualLesson allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (containerL) LoadVirtualLesson(e boil.Executor, singular bool, maybeContainer interface{}) error {
    var slice []*Container
    var object *Container

    count := 1
    if singular {
        object = maybeContainer.(*Container)
    } else {
        slice = *maybeContainer.(*[]*Container)
        count = len(slice)
    }

    args := make([]interface{}, count)
    if singular {
        if object.R == nil {
            object.R = &containerR{}
        }
        args[0] = object.VirtualLessonID
    } else {
        for i, obj := range slice {
            if obj.R == nil {
                obj.R = &containerR{}
            }
            args[i] = obj.VirtualLessonID
        }
    }

    query := fmt.Sprintf(
        "select * from \"virtual_lessons\" 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 VirtualLesson")
    }
    defer results.Close()

    var resultSlice []*VirtualLesson
    if err = queries.Bind(results, &resultSlice); err != nil {
        return errors.Wrap(err, "failed to bind eager loaded slice VirtualLesson")
    }

    if len(resultSlice) == 0 {
        return nil
    }

    if singular {
        object.R.VirtualLesson = resultSlice[0]
        return nil
    }

    for _, local := range slice {
        for _, foreign := range resultSlice {
            if local.VirtualLessonID.Int == foreign.ID {
                local.R.VirtualLesson = foreign
                break
            }
        }
    }

    return nil
}

// LoadCatalogs allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (containerL) LoadCatalogs(e boil.Executor, singular bool, maybeContainer interface{}) error {
    var slice []*Container
    var object *Container

    count := 1
    if singular {
        object = maybeContainer.(*Container)
    } else {
        slice = *maybeContainer.(*[]*Container)
        count = len(slice)
    }

    args := make([]interface{}, count)
    if singular {
        if object.R == nil {
            object.R = &containerR{}
        }
        args[0] = object.ID
    } else {
        for i, obj := range slice {
            if obj.R == nil {
                obj.R = &containerR{}
            }
            args[i] = obj.ID
        }
    }

    query := fmt.Sprintf(
        "select \"a\".*, \"b\".\"container_id\" from \"catalogs\" as \"a\" inner join \"catalogs_containers\" as \"b\" on \"a\".\"id\" = \"b\".\"catalog_id\" where \"b\".\"container_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 catalogs")
    }
    defer results.Close()

    var resultSlice []*Catalog

    var localJoinCols []int
    for results.Next() {
        one := new(Catalog)
        var localJoinCol int

        err = results.Scan(&one.ID, &one.Name, &one.ParentID, &one.CreatedAt, &one.UpdatedAt, &one.Catorder, &one.Secure, &one.Visible, &one.Open, &one.Label, &one.SelectedCatalog, &one.UserID, &one.BooksCatalog, &localJoinCol)
        if err = results.Err(); err != nil {
            return errors.Wrap(err, "failed to plebian-bind eager loaded slice catalogs")
        }

        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 catalogs")
    }

    if singular {
        object.R.Catalogs = resultSlice
        return nil
    }

    for i, foreign := range resultSlice {
        localJoinCol := localJoinCols[i]
        for _, local := range slice {
            if local.ID == localJoinCol {
                local.R.Catalogs = append(local.R.Catalogs, foreign)
                break
            }
        }
    }

    return nil
}

// LoadContainerDescriptions allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (containerL) LoadContainerDescriptions(e boil.Executor, singular bool, maybeContainer interface{}) error {
    var slice []*Container
    var object *Container

    count := 1
    if singular {
        object = maybeContainer.(*Container)
    } else {
        slice = *maybeContainer.(*[]*Container)
        count = len(slice)
    }

    args := make([]interface{}, count)
    if singular {
        if object.R == nil {
            object.R = &containerR{}
        }
        args[0] = object.ID
    } else {
        for i, obj := range slice {
            if obj.R == nil {
                obj.R = &containerR{}
            }
            args[i] = obj.ID
        }
    }

    query := fmt.Sprintf(
        "select * from \"container_descriptions\" where \"container_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 container_descriptions")
    }
    defer results.Close()

    var resultSlice []*ContainerDescription
    if err = queries.Bind(results, &resultSlice); err != nil {
        return errors.Wrap(err, "failed to bind eager loaded slice container_descriptions")
    }

    if singular {
        object.R.ContainerDescriptions = resultSlice
        return nil
    }

    for _, foreign := range resultSlice {
        for _, local := range slice {
            if local.ID == foreign.ContainerID {
                local.R.ContainerDescriptions = append(local.R.ContainerDescriptions, foreign)
                break
            }
        }
    }

    return nil
}

// LoadFileAssets allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (containerL) LoadFileAssets(e boil.Executor, singular bool, maybeContainer interface{}) error {
    var slice []*Container
    var object *Container

    count := 1
    if singular {
        object = maybeContainer.(*Container)
    } else {
        slice = *maybeContainer.(*[]*Container)
        count = len(slice)
    }

    args := make([]interface{}, count)
    if singular {
        if object.R == nil {
            object.R = &containerR{}
        }
        args[0] = object.ID
    } else {
        for i, obj := range slice {
            if obj.R == nil {
                obj.R = &containerR{}
            }
            args[i] = obj.ID
        }
    }

    query := fmt.Sprintf(
        "select \"a\".*, \"b\".\"container_id\" from \"file_assets\" as \"a\" inner join \"containers_file_assets\" as \"b\" on \"a\".\"id\" = \"b\".\"file_asset_id\" where \"b\".\"container_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_assets")
    }
    defer results.Close()

    var resultSlice []*FileAsset

    var localJoinCols []int
    for results.Next() {
        one := new(FileAsset)
        var localJoinCol int

        err = results.Scan(&one.ID, &one.Name, &one.LangID, &one.AssetType, &one.Date, &one.Size, &one.ServernameID, &one.Status, &one.CreatedAt, &one.UpdatedAt, &one.Lastuser, &one.Clicks, &one.Secure, &one.PlaytimeSecs, &one.UserID, &one.Sha1, &localJoinCol)
        if err = results.Err(); err != nil {
            return errors.Wrap(err, "failed to plebian-bind eager loaded slice file_assets")
        }

        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 file_assets")
    }

    if singular {
        object.R.FileAssets = resultSlice
        return nil
    }

    for i, foreign := range resultSlice {
        localJoinCol := localJoinCols[i]
        for _, local := range slice {
            if local.ID == localJoinCol {
                local.R.FileAssets = append(local.R.FileAssets, foreign)
                break
            }
        }
    }

    return nil
}

// LoadLabels allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (containerL) LoadLabels(e boil.Executor, singular bool, maybeContainer interface{}) error {
    var slice []*Container
    var object *Container

    count := 1
    if singular {
        object = maybeContainer.(*Container)
    } else {
        slice = *maybeContainer.(*[]*Container)
        count = len(slice)
    }

    args := make([]interface{}, count)
    if singular {
        if object.R == nil {
            object.R = &containerR{}
        }
        args[0] = object.ID
    } else {
        for i, obj := range slice {
            if obj.R == nil {
                obj.R = &containerR{}
            }
            args[i] = obj.ID
        }
    }

    query := fmt.Sprintf(
        "select \"a\".*, \"b\".\"container_id\" from \"labels\" as \"a\" inner join \"containers_labels\" as \"b\" on \"a\".\"id\" = \"b\".\"label_id\" where \"b\".\"container_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 labels")
    }
    defer results.Close()

    var resultSlice []*Label

    var localJoinCols []int
    for results.Next() {
        one := new(Label)
        var localJoinCol int

        err = results.Scan(&one.ID, &one.DictionaryID, &one.Suid, &one.CreatedAt, &one.UpdatedAt, &localJoinCol)
        if err = results.Err(); err != nil {
            return errors.Wrap(err, "failed to plebian-bind eager loaded slice labels")
        }

        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 labels")
    }

    if singular {
        object.R.Labels = resultSlice
        return nil
    }

    for i, foreign := range resultSlice {
        localJoinCol := localJoinCols[i]
        for _, local := range slice {
            if local.ID == localJoinCol {
                local.R.Labels = append(local.R.Labels, foreign)
                break
            }
        }
    }

    return nil
}

// SetContentTypeG of the container to the related item.
// Sets o.R.ContentType to related.
// Adds o to related.R.Containers.
// Uses the global database handle.
func (o *Container) SetContentTypeG(insert bool, related *ContentType) error {
    return o.SetContentType(boil.GetDB(), insert, related)
}

// SetContentTypeP of the container to the related item.
// Sets o.R.ContentType to related.
// Adds o to related.R.Containers.
// Panics on error.
func (o *Container) SetContentTypeP(exec boil.Executor, insert bool, related *ContentType) {
    if err := o.SetContentType(exec, insert, related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetContentTypeGP of the container to the related item.
// Sets o.R.ContentType to related.
// Adds o to related.R.Containers.
// Uses the global database handle and panics on error.
func (o *Container) SetContentTypeGP(insert bool, related *ContentType) {
    if err := o.SetContentType(boil.GetDB(), insert, related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetContentType of the container to the related item.
// Sets o.R.ContentType to related.
// Adds o to related.R.Containers.
func (o *Container) SetContentType(exec boil.Executor, insert bool, related *ContentType) 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 \"containers\" SET %s WHERE %s",
        strmangle.SetParamNames("\"", "\"", 1, []string{"content_type_id"}),
        strmangle.WhereClause("\"", "\"", 2, containerPrimaryKeyColumns),
    )
    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.ContentTypeID.Int = related.ID
    o.ContentTypeID.Valid = true

    if o.R == nil {
        o.R = &containerR{
            ContentType: related,
        }
    } else {
        o.R.ContentType = related
    }

    if related.R == nil {
        related.R = &contentTypeR{
            Containers: ContainerSlice{o},
        }
    } else {
        related.R.Containers = append(related.R.Containers, o)
    }

    return nil
}

// RemoveContentTypeG relationship.
// Sets o.R.ContentType to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle.
func (o *Container) RemoveContentTypeG(related *ContentType) error {
    return o.RemoveContentType(boil.GetDB(), related)
}

// RemoveContentTypeP relationship.
// Sets o.R.ContentType to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Panics on error.
func (o *Container) RemoveContentTypeP(exec boil.Executor, related *ContentType) {
    if err := o.RemoveContentType(exec, related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveContentTypeGP relationship.
// Sets o.R.ContentType to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle and panics on error.
func (o *Container) RemoveContentTypeGP(related *ContentType) {
    if err := o.RemoveContentType(boil.GetDB(), related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveContentType relationship.
// Sets o.R.ContentType to nil.
// Removes o from all passed in related items' relationships struct (Optional).
func (o *Container) RemoveContentType(exec boil.Executor, related *ContentType) error {
    var err error

    o.ContentTypeID.Valid = false
    if err = o.Update(exec, "content_type_id"); err != nil {
        o.ContentTypeID.Valid = true
        return errors.Wrap(err, "failed to update local table")
    }

    o.R.ContentType = nil
    if related == nil || related.R == nil {
        return nil
    }

    for i, ri := range related.R.Containers {
        if o.ContentTypeID.Int != ri.ContentTypeID.Int {
            continue
        }

        ln := len(related.R.Containers)
        if ln > 1 && i < ln-1 {
            related.R.Containers[i] = related.R.Containers[ln-1]
        }
        related.R.Containers = related.R.Containers[:ln-1]
        break
    }
    return nil
}

// SetLangG of the container to the related item.
// Sets o.R.Lang to related.
// Adds o to related.R.LangContainers.
// Uses the global database handle.
func (o *Container) SetLangG(insert bool, related *Language) error {
    return o.SetLang(boil.GetDB(), insert, related)
}

// SetLangP of the container to the related item.
// Sets o.R.Lang to related.
// Adds o to related.R.LangContainers.
// Panics on error.
func (o *Container) SetLangP(exec boil.Executor, insert bool, related *Language) {
    if err := o.SetLang(exec, insert, related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetLangGP of the container to the related item.
// Sets o.R.Lang to related.
// Adds o to related.R.LangContainers.
// Uses the global database handle and panics on error.
func (o *Container) SetLangGP(insert bool, related *Language) {
    if err := o.SetLang(boil.GetDB(), insert, related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetLang of the container to the related item.
// Sets o.R.Lang to related.
// Adds o to related.R.LangContainers.
func (o *Container) SetLang(exec boil.Executor, insert bool, related *Language) 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 \"containers\" SET %s WHERE %s",
        strmangle.SetParamNames("\"", "\"", 1, []string{"lang_id"}),
        strmangle.WhereClause("\"", "\"", 2, containerPrimaryKeyColumns),
    )
    values := []interface{}{related.Code3, 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.LangID.String = related.Code3.String
    o.LangID.Valid = true

    if o.R == nil {
        o.R = &containerR{
            Lang: related,
        }
    } else {
        o.R.Lang = related
    }

    if related.R == nil {
        related.R = &languageR{
            LangContainers: ContainerSlice{o},
        }
    } else {
        related.R.LangContainers = append(related.R.LangContainers, o)
    }

    return nil
}

// RemoveLangG relationship.
// Sets o.R.Lang to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle.
func (o *Container) RemoveLangG(related *Language) error {
    return o.RemoveLang(boil.GetDB(), related)
}

// RemoveLangP relationship.
// Sets o.R.Lang to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Panics on error.
func (o *Container) RemoveLangP(exec boil.Executor, related *Language) {
    if err := o.RemoveLang(exec, related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveLangGP relationship.
// Sets o.R.Lang to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle and panics on error.
func (o *Container) RemoveLangGP(related *Language) {
    if err := o.RemoveLang(boil.GetDB(), related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveLang relationship.
// Sets o.R.Lang to nil.
// Removes o from all passed in related items' relationships struct (Optional).
func (o *Container) RemoveLang(exec boil.Executor, related *Language) error {
    var err error

    o.LangID.Valid = false
    if err = o.Update(exec, "lang_id"); err != nil {
        o.LangID.Valid = true
        return errors.Wrap(err, "failed to update local table")
    }

    o.R.Lang = nil
    if related == nil || related.R == nil {
        return nil
    }

    for i, ri := range related.R.LangContainers {
        if o.LangID.String != ri.LangID.String {
            continue
        }

        ln := len(related.R.LangContainers)
        if ln > 1 && i < ln-1 {
            related.R.LangContainers[i] = related.R.LangContainers[ln-1]
        }
        related.R.LangContainers = related.R.LangContainers[:ln-1]
        break
    }
    return nil
}

// SetVirtualLessonG of the container to the related item.
// Sets o.R.VirtualLesson to related.
// Adds o to related.R.Containers.
// Uses the global database handle.
func (o *Container) SetVirtualLessonG(insert bool, related *VirtualLesson) error {
    return o.SetVirtualLesson(boil.GetDB(), insert, related)
}

// SetVirtualLessonP of the container to the related item.
// Sets o.R.VirtualLesson to related.
// Adds o to related.R.Containers.
// Panics on error.
func (o *Container) SetVirtualLessonP(exec boil.Executor, insert bool, related *VirtualLesson) {
    if err := o.SetVirtualLesson(exec, insert, related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetVirtualLessonGP of the container to the related item.
// Sets o.R.VirtualLesson to related.
// Adds o to related.R.Containers.
// Uses the global database handle and panics on error.
func (o *Container) SetVirtualLessonGP(insert bool, related *VirtualLesson) {
    if err := o.SetVirtualLesson(boil.GetDB(), insert, related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetVirtualLesson of the container to the related item.
// Sets o.R.VirtualLesson to related.
// Adds o to related.R.Containers.
func (o *Container) SetVirtualLesson(exec boil.Executor, insert bool, related *VirtualLesson) 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 \"containers\" SET %s WHERE %s",
        strmangle.SetParamNames("\"", "\"", 1, []string{"virtual_lesson_id"}),
        strmangle.WhereClause("\"", "\"", 2, containerPrimaryKeyColumns),
    )
    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.VirtualLessonID.Int = related.ID
    o.VirtualLessonID.Valid = true

    if o.R == nil {
        o.R = &containerR{
            VirtualLesson: related,
        }
    } else {
        o.R.VirtualLesson = related
    }

    if related.R == nil {
        related.R = &virtualLessonR{
            Containers: ContainerSlice{o},
        }
    } else {
        related.R.Containers = append(related.R.Containers, o)
    }

    return nil
}

// RemoveVirtualLessonG relationship.
// Sets o.R.VirtualLesson to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle.
func (o *Container) RemoveVirtualLessonG(related *VirtualLesson) error {
    return o.RemoveVirtualLesson(boil.GetDB(), related)
}

// RemoveVirtualLessonP relationship.
// Sets o.R.VirtualLesson to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Panics on error.
func (o *Container) RemoveVirtualLessonP(exec boil.Executor, related *VirtualLesson) {
    if err := o.RemoveVirtualLesson(exec, related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveVirtualLessonGP relationship.
// Sets o.R.VirtualLesson to nil.
// Removes o from all passed in related items' relationships struct (Optional).
// Uses the global database handle and panics on error.
func (o *Container) RemoveVirtualLessonGP(related *VirtualLesson) {
    if err := o.RemoveVirtualLesson(boil.GetDB(), related); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveVirtualLesson relationship.
// Sets o.R.VirtualLesson to nil.
// Removes o from all passed in related items' relationships struct (Optional).
func (o *Container) RemoveVirtualLesson(exec boil.Executor, related *VirtualLesson) error {
    var err error

    o.VirtualLessonID.Valid = false
    if err = o.Update(exec, "virtual_lesson_id"); err != nil {
        o.VirtualLessonID.Valid = true
        return errors.Wrap(err, "failed to update local table")
    }

    o.R.VirtualLesson = nil
    if related == nil || related.R == nil {
        return nil
    }

    for i, ri := range related.R.Containers {
        if o.VirtualLessonID.Int != ri.VirtualLessonID.Int {
            continue
        }

        ln := len(related.R.Containers)
        if ln > 1 && i < ln-1 {
            related.R.Containers[i] = related.R.Containers[ln-1]
        }
        related.R.Containers = related.R.Containers[:ln-1]
        break
    }
    return nil
}

// AddCatalogsG adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.Catalogs.
// Sets related.R.Containers appropriately.
// Uses the global database handle.
func (o *Container) AddCatalogsG(insert bool, related ...*Catalog) error {
    return o.AddCatalogs(boil.GetDB(), insert, related...)
}

// AddCatalogsP adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.Catalogs.
// Sets related.R.Containers appropriately.
// Panics on error.
func (o *Container) AddCatalogsP(exec boil.Executor, insert bool, related ...*Catalog) {
    if err := o.AddCatalogs(exec, insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// AddCatalogsGP adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.Catalogs.
// Sets related.R.Containers appropriately.
// Uses the global database handle and panics on error.
func (o *Container) AddCatalogsGP(insert bool, related ...*Catalog) {
    if err := o.AddCatalogs(boil.GetDB(), insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// AddCatalogs adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.Catalogs.
// Sets related.R.Containers appropriately.
func (o *Container) AddCatalogs(exec boil.Executor, insert bool, related ...*Catalog) 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 \"catalogs_containers\" (\"container_id\", \"catalog_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 = &containerR{
            Catalogs: related,
        }
    } else {
        o.R.Catalogs = append(o.R.Catalogs, related...)
    }

    for _, rel := range related {
        if rel.R == nil {
            rel.R = &catalogR{
                Containers: ContainerSlice{o},
            }
        } else {
            rel.R.Containers = append(rel.R.Containers, o)
        }
    }
    return nil
}

// SetCatalogsG removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's Catalogs accordingly.
// Replaces o.R.Catalogs with related.
// Sets related.R.Containers's Catalogs accordingly.
// Uses the global database handle.
func (o *Container) SetCatalogsG(insert bool, related ...*Catalog) error {
    return o.SetCatalogs(boil.GetDB(), insert, related...)
}

// SetCatalogsP removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's Catalogs accordingly.
// Replaces o.R.Catalogs with related.
// Sets related.R.Containers's Catalogs accordingly.
// Panics on error.
func (o *Container) SetCatalogsP(exec boil.Executor, insert bool, related ...*Catalog) {
    if err := o.SetCatalogs(exec, insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetCatalogsGP removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's Catalogs accordingly.
// Replaces o.R.Catalogs with related.
// Sets related.R.Containers's Catalogs accordingly.
// Uses the global database handle and panics on error.
func (o *Container) SetCatalogsGP(insert bool, related ...*Catalog) {
    if err := o.SetCatalogs(boil.GetDB(), insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetCatalogs removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's Catalogs accordingly.
// Replaces o.R.Catalogs with related.
// Sets related.R.Containers's Catalogs accordingly.
func (o *Container) SetCatalogs(exec boil.Executor, insert bool, related ...*Catalog) error {
    query := "delete from \"catalogs_containers\" where \"container_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")
    }

    removeCatalogsFromContainersSlice(o, related)
    if o.R != nil {
        o.R.Catalogs = nil
    }
    return o.AddCatalogs(exec, insert, related...)
}

// RemoveCatalogsG relationships from objects passed in.
// Removes related items from R.Catalogs (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
// Uses the global database handle.
func (o *Container) RemoveCatalogsG(related ...*Catalog) error {
    return o.RemoveCatalogs(boil.GetDB(), related...)
}

// RemoveCatalogsP relationships from objects passed in.
// Removes related items from R.Catalogs (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
// Panics on error.
func (o *Container) RemoveCatalogsP(exec boil.Executor, related ...*Catalog) {
    if err := o.RemoveCatalogs(exec, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveCatalogsGP relationships from objects passed in.
// Removes related items from R.Catalogs (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
// Uses the global database handle and panics on error.
func (o *Container) RemoveCatalogsGP(related ...*Catalog) {
    if err := o.RemoveCatalogs(boil.GetDB(), related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveCatalogs relationships from objects passed in.
// Removes related items from R.Catalogs (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
func (o *Container) RemoveCatalogs(exec boil.Executor, related ...*Catalog) error {
    var err error
    query := fmt.Sprintf(
        "delete from \"catalogs_containers\" where \"container_id\" = $1 and \"catalog_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")
    }
    removeCatalogsFromContainersSlice(o, related)
    if o.R == nil {
        return nil
    }

    for _, rel := range related {
        for i, ri := range o.R.Catalogs {
            if rel != ri {
                continue
            }

            ln := len(o.R.Catalogs)
            if ln > 1 && i < ln-1 {
                o.R.Catalogs[i] = o.R.Catalogs[ln-1]
            }
            o.R.Catalogs = o.R.Catalogs[:ln-1]
            break
        }
    }

    return nil
}

func removeCatalogsFromContainersSlice(o *Container, related []*Catalog) {
    for _, rel := range related {
        if rel.R == nil {
            continue
        }
        for i, ri := range rel.R.Containers {
            if o.ID != ri.ID {
                continue
            }

            ln := len(rel.R.Containers)
            if ln > 1 && i < ln-1 {
                rel.R.Containers[i] = rel.R.Containers[ln-1]
            }
            rel.R.Containers = rel.R.Containers[:ln-1]
            break
        }
    }
}

// AddContainerDescriptionsG adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.ContainerDescriptions.
// Sets related.R.Container appropriately.
// Uses the global database handle.
func (o *Container) AddContainerDescriptionsG(insert bool, related ...*ContainerDescription) error {
    return o.AddContainerDescriptions(boil.GetDB(), insert, related...)
}

// AddContainerDescriptionsP adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.ContainerDescriptions.
// Sets related.R.Container appropriately.
// Panics on error.
func (o *Container) AddContainerDescriptionsP(exec boil.Executor, insert bool, related ...*ContainerDescription) {
    if err := o.AddContainerDescriptions(exec, insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// AddContainerDescriptionsGP adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.ContainerDescriptions.
// Sets related.R.Container appropriately.
// Uses the global database handle and panics on error.
func (o *Container) AddContainerDescriptionsGP(insert bool, related ...*ContainerDescription) {
    if err := o.AddContainerDescriptions(boil.GetDB(), insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// AddContainerDescriptions adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.ContainerDescriptions.
// Sets related.R.Container appropriately.
func (o *Container) AddContainerDescriptions(exec boil.Executor, insert bool, related ...*ContainerDescription) error {
    var err error
    for _, rel := range related {
        if insert {
            rel.ContainerID = o.ID
            if err = rel.Insert(exec); err != nil {
                return errors.Wrap(err, "failed to insert into foreign table")
            }
        } else {
            updateQuery := fmt.Sprintf(
                "UPDATE \"container_descriptions\" SET %s WHERE %s",
                strmangle.SetParamNames("\"", "\"", 1, []string{"container_id"}),
                strmangle.WhereClause("\"", "\"", 2, containerDescriptionPrimaryKeyColumns),
            )
            values := []interface{}{o.ID, rel.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 foreign table")
            }

            rel.ContainerID = o.ID
        }
    }

    if o.R == nil {
        o.R = &containerR{
            ContainerDescriptions: related,
        }
    } else {
        o.R.ContainerDescriptions = append(o.R.ContainerDescriptions, related...)
    }

    for _, rel := range related {
        if rel.R == nil {
            rel.R = &containerDescriptionR{
                Container: o,
            }
        } else {
            rel.R.Container = o
        }
    }
    return nil
}

// AddFileAssetsG adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.FileAssets.
// Sets related.R.Containers appropriately.
// Uses the global database handle.
func (o *Container) AddFileAssetsG(insert bool, related ...*FileAsset) error {
    return o.AddFileAssets(boil.GetDB(), insert, related...)
}

// AddFileAssetsP adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.FileAssets.
// Sets related.R.Containers appropriately.
// Panics on error.
func (o *Container) AddFileAssetsP(exec boil.Executor, insert bool, related ...*FileAsset) {
    if err := o.AddFileAssets(exec, insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// AddFileAssetsGP adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.FileAssets.
// Sets related.R.Containers appropriately.
// Uses the global database handle and panics on error.
func (o *Container) AddFileAssetsGP(insert bool, related ...*FileAsset) {
    if err := o.AddFileAssets(boil.GetDB(), insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// AddFileAssets adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.FileAssets.
// Sets related.R.Containers appropriately.
func (o *Container) AddFileAssets(exec boil.Executor, insert bool, related ...*FileAsset) 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 \"containers_file_assets\" (\"container_id\", \"file_asset_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 = &containerR{
            FileAssets: related,
        }
    } else {
        o.R.FileAssets = append(o.R.FileAssets, related...)
    }

    for _, rel := range related {
        if rel.R == nil {
            rel.R = &fileAssetR{
                Containers: ContainerSlice{o},
            }
        } else {
            rel.R.Containers = append(rel.R.Containers, o)
        }
    }
    return nil
}

// SetFileAssetsG removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's FileAssets accordingly.
// Replaces o.R.FileAssets with related.
// Sets related.R.Containers's FileAssets accordingly.
// Uses the global database handle.
func (o *Container) SetFileAssetsG(insert bool, related ...*FileAsset) error {
    return o.SetFileAssets(boil.GetDB(), insert, related...)
}

// SetFileAssetsP removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's FileAssets accordingly.
// Replaces o.R.FileAssets with related.
// Sets related.R.Containers's FileAssets accordingly.
// Panics on error.
func (o *Container) SetFileAssetsP(exec boil.Executor, insert bool, related ...*FileAsset) {
    if err := o.SetFileAssets(exec, insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetFileAssetsGP removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's FileAssets accordingly.
// Replaces o.R.FileAssets with related.
// Sets related.R.Containers's FileAssets accordingly.
// Uses the global database handle and panics on error.
func (o *Container) SetFileAssetsGP(insert bool, related ...*FileAsset) {
    if err := o.SetFileAssets(boil.GetDB(), insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetFileAssets removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's FileAssets accordingly.
// Replaces o.R.FileAssets with related.
// Sets related.R.Containers's FileAssets accordingly.
func (o *Container) SetFileAssets(exec boil.Executor, insert bool, related ...*FileAsset) error {
    query := "delete from \"containers_file_assets\" where \"container_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")
    }

    removeFileAssetsFromContainersSlice(o, related)
    if o.R != nil {
        o.R.FileAssets = nil
    }
    return o.AddFileAssets(exec, insert, related...)
}

// RemoveFileAssetsG relationships from objects passed in.
// Removes related items from R.FileAssets (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
// Uses the global database handle.
func (o *Container) RemoveFileAssetsG(related ...*FileAsset) error {
    return o.RemoveFileAssets(boil.GetDB(), related...)
}

// RemoveFileAssetsP relationships from objects passed in.
// Removes related items from R.FileAssets (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
// Panics on error.
func (o *Container) RemoveFileAssetsP(exec boil.Executor, related ...*FileAsset) {
    if err := o.RemoveFileAssets(exec, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveFileAssetsGP relationships from objects passed in.
// Removes related items from R.FileAssets (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
// Uses the global database handle and panics on error.
func (o *Container) RemoveFileAssetsGP(related ...*FileAsset) {
    if err := o.RemoveFileAssets(boil.GetDB(), related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveFileAssets relationships from objects passed in.
// Removes related items from R.FileAssets (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
func (o *Container) RemoveFileAssets(exec boil.Executor, related ...*FileAsset) error {
    var err error
    query := fmt.Sprintf(
        "delete from \"containers_file_assets\" where \"container_id\" = $1 and \"file_asset_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")
    }
    removeFileAssetsFromContainersSlice(o, related)
    if o.R == nil {
        return nil
    }

    for _, rel := range related {
        for i, ri := range o.R.FileAssets {
            if rel != ri {
                continue
            }

            ln := len(o.R.FileAssets)
            if ln > 1 && i < ln-1 {
                o.R.FileAssets[i] = o.R.FileAssets[ln-1]
            }
            o.R.FileAssets = o.R.FileAssets[:ln-1]
            break
        }
    }

    return nil
}

func removeFileAssetsFromContainersSlice(o *Container, related []*FileAsset) {
    for _, rel := range related {
        if rel.R == nil {
            continue
        }
        for i, ri := range rel.R.Containers {
            if o.ID != ri.ID {
                continue
            }

            ln := len(rel.R.Containers)
            if ln > 1 && i < ln-1 {
                rel.R.Containers[i] = rel.R.Containers[ln-1]
            }
            rel.R.Containers = rel.R.Containers[:ln-1]
            break
        }
    }
}

// AddLabelsG adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.Labels.
// Sets related.R.Containers appropriately.
// Uses the global database handle.
func (o *Container) AddLabelsG(insert bool, related ...*Label) error {
    return o.AddLabels(boil.GetDB(), insert, related...)
}

// AddLabelsP adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.Labels.
// Sets related.R.Containers appropriately.
// Panics on error.
func (o *Container) AddLabelsP(exec boil.Executor, insert bool, related ...*Label) {
    if err := o.AddLabels(exec, insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// AddLabelsGP adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.Labels.
// Sets related.R.Containers appropriately.
// Uses the global database handle and panics on error.
func (o *Container) AddLabelsGP(insert bool, related ...*Label) {
    if err := o.AddLabels(boil.GetDB(), insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// AddLabels adds the given related objects to the existing relationships
// of the container, optionally inserting them as new records.
// Appends related to o.R.Labels.
// Sets related.R.Containers appropriately.
func (o *Container) AddLabels(exec boil.Executor, insert bool, related ...*Label) 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 \"containers_labels\" (\"container_id\", \"label_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 = &containerR{
            Labels: related,
        }
    } else {
        o.R.Labels = append(o.R.Labels, related...)
    }

    for _, rel := range related {
        if rel.R == nil {
            rel.R = &labelR{
                Containers: ContainerSlice{o},
            }
        } else {
            rel.R.Containers = append(rel.R.Containers, o)
        }
    }
    return nil
}

// SetLabelsG removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's Labels accordingly.
// Replaces o.R.Labels with related.
// Sets related.R.Containers's Labels accordingly.
// Uses the global database handle.
func (o *Container) SetLabelsG(insert bool, related ...*Label) error {
    return o.SetLabels(boil.GetDB(), insert, related...)
}

// SetLabelsP removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's Labels accordingly.
// Replaces o.R.Labels with related.
// Sets related.R.Containers's Labels accordingly.
// Panics on error.
func (o *Container) SetLabelsP(exec boil.Executor, insert bool, related ...*Label) {
    if err := o.SetLabels(exec, insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetLabelsGP removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's Labels accordingly.
// Replaces o.R.Labels with related.
// Sets related.R.Containers's Labels accordingly.
// Uses the global database handle and panics on error.
func (o *Container) SetLabelsGP(insert bool, related ...*Label) {
    if err := o.SetLabels(boil.GetDB(), insert, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// SetLabels removes all previously related items of the
// container replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Containers's Labels accordingly.
// Replaces o.R.Labels with related.
// Sets related.R.Containers's Labels accordingly.
func (o *Container) SetLabels(exec boil.Executor, insert bool, related ...*Label) error {
    query := "delete from \"containers_labels\" where \"container_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")
    }

    removeLabelsFromContainersSlice(o, related)
    if o.R != nil {
        o.R.Labels = nil
    }
    return o.AddLabels(exec, insert, related...)
}

// RemoveLabelsG relationships from objects passed in.
// Removes related items from R.Labels (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
// Uses the global database handle.
func (o *Container) RemoveLabelsG(related ...*Label) error {
    return o.RemoveLabels(boil.GetDB(), related...)
}

// RemoveLabelsP relationships from objects passed in.
// Removes related items from R.Labels (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
// Panics on error.
func (o *Container) RemoveLabelsP(exec boil.Executor, related ...*Label) {
    if err := o.RemoveLabels(exec, related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveLabelsGP relationships from objects passed in.
// Removes related items from R.Labels (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
// Uses the global database handle and panics on error.
func (o *Container) RemoveLabelsGP(related ...*Label) {
    if err := o.RemoveLabels(boil.GetDB(), related...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// RemoveLabels relationships from objects passed in.
// Removes related items from R.Labels (uses pointer comparison, removal does not keep order)
// Sets related.R.Containers.
func (o *Container) RemoveLabels(exec boil.Executor, related ...*Label) error {
    var err error
    query := fmt.Sprintf(
        "delete from \"containers_labels\" where \"container_id\" = $1 and \"label_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")
    }
    removeLabelsFromContainersSlice(o, related)
    if o.R == nil {
        return nil
    }

    for _, rel := range related {
        for i, ri := range o.R.Labels {
            if rel != ri {
                continue
            }

            ln := len(o.R.Labels)
            if ln > 1 && i < ln-1 {
                o.R.Labels[i] = o.R.Labels[ln-1]
            }
            o.R.Labels = o.R.Labels[:ln-1]
            break
        }
    }

    return nil
}

func removeLabelsFromContainersSlice(o *Container, related []*Label) {
    for _, rel := range related {
        if rel.R == nil {
            continue
        }
        for i, ri := range rel.R.Containers {
            if o.ID != ri.ID {
                continue
            }

            ln := len(rel.R.Containers)
            if ln > 1 && i < ln-1 {
                rel.R.Containers[i] = rel.R.Containers[ln-1]
            }
            rel.R.Containers = rel.R.Containers[:ln-1]
            break
        }
    }
}

// ContainersG retrieves all records.
func ContainersG(mods ...qm.QueryMod) containerQuery {
    return Containers(boil.GetDB(), mods...)
}

// Containers retrieves all the records using an executor.
func Containers(exec boil.Executor, mods ...qm.QueryMod) containerQuery {
    mods = append(mods, qm.From("\"containers\""))
    return containerQuery{NewQuery(exec, mods...)}
}

// FindContainerG retrieves a single record by ID.
func FindContainerG(id int, selectCols ...string) (*Container, error) {
    return FindContainer(boil.GetDB(), id, selectCols...)
}

// FindContainerGP retrieves a single record by ID, and panics on error.
func FindContainerGP(id int, selectCols ...string) *Container {
    retobj, err := FindContainer(boil.GetDB(), id, selectCols...)
    if err != nil {
        panic(boil.WrapErr(err))
    }

    return retobj
}

// FindContainer retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindContainer(exec boil.Executor, id int, selectCols ...string) (*Container, error) {
    containerObj := &Container{}

    sel := "*"
    if len(selectCols) > 0 {
        sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
    }
    query := fmt.Sprintf(
        "select %s from \"containers\" where \"id\"=$1", sel,
    )

    q := queries.Raw(exec, query, id)

    err := q.Bind(containerObj)
    if err != nil {
        if errors.Cause(err) == sql.ErrNoRows {
            return nil, sql.ErrNoRows
        }
        return nil, errors.Wrap(err, "kmodels: unable to select from containers")
    }

    return containerObj, nil
}

// FindContainerP retrieves a single record by ID with an executor, and panics on error.
func FindContainerP(exec boil.Executor, id int, selectCols ...string) *Container {
    retobj, err := FindContainer(exec, id, selectCols...)
    if err != nil {
        panic(boil.WrapErr(err))
    }

    return retobj
}

// InsertG a single record. See Insert for whitelist behavior description.
func (o *Container) InsertG(whitelist ...string) error {
    return o.Insert(boil.GetDB(), whitelist...)
}

// InsertGP a single record, and panics on error. See Insert for whitelist
// behavior description.
func (o *Container) InsertGP(whitelist ...string) {
    if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// InsertP a single record using an executor, and panics on error. See Insert
// for whitelist behavior description.
func (o *Container) InsertP(exec boil.Executor, whitelist ...string) {
    if err := o.Insert(exec, whitelist...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// Insert a single record using an executor.
// Whitelist behavior: If a whitelist is provided, only those columns supplied are inserted
// No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
// - All columns without a default value are included (i.e. name, age)
// - All columns with a default, but non-zero are included (i.e. health = 75)
func (o *Container) Insert(exec boil.Executor, whitelist ...string) error {
    if o == nil {
        return errors.New("kmodels: no containers provided for insertion")
    }

    var err error
    currTime := time.Now().In(boil.GetLocation())

    if o.CreatedAt.Time.IsZero() {
        o.CreatedAt.Time = currTime
        o.CreatedAt.Valid = true
    }
    if o.UpdatedAt.Time.IsZero() {
        o.UpdatedAt.Time = currTime
        o.UpdatedAt.Valid = true
    }

    nzDefaults := queries.NonZeroDefaultSet(containerColumnsWithDefault, o)

    key := makeCacheKey(whitelist, nzDefaults)
    containerInsertCacheMut.RLock()
    cache, cached := containerInsertCache[key]
    containerInsertCacheMut.RUnlock()

    if !cached {
        wl, returnColumns := strmangle.InsertColumnSet(
            containerColumns,
            containerColumnsWithDefault,
            containerColumnsWithoutDefault,
            nzDefaults,
            whitelist,
        )

        cache.valueMapping, err = queries.BindMapping(containerType, containerMapping, wl)
        if err != nil {
            return err
        }
        cache.retMapping, err = queries.BindMapping(containerType, containerMapping, returnColumns)
        if err != nil {
            return err
        }
        if len(wl) != 0 {
            cache.query = fmt.Sprintf("INSERT INTO \"containers\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
        } else {
            cache.query = "INSERT INTO \"containers\" DEFAULT VALUES"
        }

        var queryOutput, queryReturning string

        if len(cache.retMapping) != 0 {
            queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
        }

        if len(wl) != 0 {
            cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
        }
    }

    value := reflect.Indirect(reflect.ValueOf(o))
    vals := queries.ValuesFromMapping(value, cache.valueMapping)

    if boil.DebugMode {
        fmt.Fprintln(boil.DebugWriter, cache.query)
        fmt.Fprintln(boil.DebugWriter, vals)
    }

    if len(cache.retMapping) != 0 {
        err = exec.QueryRow(cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
    } else {
        _, err = exec.Exec(cache.query, vals...)
    }

    if err != nil {
        return errors.Wrap(err, "kmodels: unable to insert into containers")
    }

    if !cached {
        containerInsertCacheMut.Lock()
        containerInsertCache[key] = cache
        containerInsertCacheMut.Unlock()
    }

    return nil
}

// UpdateG a single Container record. See Update for
// whitelist behavior description.
func (o *Container) UpdateG(whitelist ...string) error {
    return o.Update(boil.GetDB(), whitelist...)
}

// UpdateGP a single Container record.
// UpdateGP takes a whitelist of column names that should be updated.
// Panics on error. See Update for whitelist behavior description.
func (o *Container) UpdateGP(whitelist ...string) {
    if err := o.Update(boil.GetDB(), whitelist...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// UpdateP uses an executor to update the Container, and panics on error.
// See Update for whitelist behavior description.
func (o *Container) UpdateP(exec boil.Executor, whitelist ...string) {
    err := o.Update(exec, whitelist...)
    if err != nil {
        panic(boil.WrapErr(err))
    }
}

// Update uses an executor to update the Container.
// Whitelist behavior: If a whitelist is provided, only the columns given are updated.
// No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
// - All columns are inferred to start with
// - All primary keys are subtracted from this set
// Update does not automatically update the record in case of default values. Use .Reload()
// to refresh the records.
func (o *Container) Update(exec boil.Executor, whitelist ...string) error {
    currTime := time.Now().In(boil.GetLocation())

    o.UpdatedAt.Time = currTime
    o.UpdatedAt.Valid = true

    var err error
    key := makeCacheKey(whitelist, nil)
    containerUpdateCacheMut.RLock()
    cache, cached := containerUpdateCache[key]
    containerUpdateCacheMut.RUnlock()

    if !cached {
        wl := strmangle.UpdateColumnSet(
            containerColumns,
            containerPrimaryKeyColumns,
            whitelist,
        )

        if len(whitelist) == 0 {
            wl = strmangle.SetComplement(wl, []string{"created_at"})
        }
        if len(wl) == 0 {
            return errors.New("kmodels: unable to update containers, could not build whitelist")
        }

        cache.query = fmt.Sprintf("UPDATE \"containers\" SET %s WHERE %s",
            strmangle.SetParamNames("\"", "\"", 1, wl),
            strmangle.WhereClause("\"", "\"", len(wl)+1, containerPrimaryKeyColumns),
        )
        cache.valueMapping, err = queries.BindMapping(containerType, containerMapping, append(wl, containerPrimaryKeyColumns...))
        if err != nil {
            return err
        }
    }

    values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)

    if boil.DebugMode {
        fmt.Fprintln(boil.DebugWriter, cache.query)
        fmt.Fprintln(boil.DebugWriter, values)
    }

    _, err = exec.Exec(cache.query, values...)
    if err != nil {
        return errors.Wrap(err, "kmodels: unable to update containers row")
    }

    if !cached {
        containerUpdateCacheMut.Lock()
        containerUpdateCache[key] = cache
        containerUpdateCacheMut.Unlock()
    }

    return nil
}

// UpdateAllP updates all rows with matching column names, and panics on error.
func (q containerQuery) UpdateAllP(cols M) {
    if err := q.UpdateAll(cols); err != nil {
        panic(boil.WrapErr(err))
    }
}

// UpdateAll updates all rows with the specified column values.
func (q containerQuery) UpdateAll(cols M) error {
    queries.SetUpdate(q.Query, cols)

    _, err := q.Query.Exec()
    if err != nil {
        return errors.Wrap(err, "kmodels: unable to update all for containers")
    }

    return nil
}

// UpdateAllG updates all rows with the specified column values.
func (o ContainerSlice) UpdateAllG(cols M) error {
    return o.UpdateAll(boil.GetDB(), cols)
}

// UpdateAllGP updates all rows with the specified column values, and panics on error.
func (o ContainerSlice) UpdateAllGP(cols M) {
    if err := o.UpdateAll(boil.GetDB(), cols); err != nil {
        panic(boil.WrapErr(err))
    }
}

// UpdateAllP updates all rows with the specified column values, and panics on error.
func (o ContainerSlice) UpdateAllP(exec boil.Executor, cols M) {
    if err := o.UpdateAll(exec, cols); err != nil {
        panic(boil.WrapErr(err))
    }
}

// UpdateAll updates all rows with the specified column values, using an executor.
func (o ContainerSlice) UpdateAll(exec boil.Executor, cols M) error {
    ln := int64(len(o))
    if ln == 0 {
        return nil
    }

    if len(cols) == 0 {
        return errors.New("kmodels: update all requires at least one column argument")
    }

    colNames := make([]string, len(cols))
    args := make([]interface{}, len(cols))

    i := 0
    for name, value := range cols {
        colNames[i] = name
        args[i] = value
        i++
    }

    // Append all of the primary key values for each column
    for _, obj := range o {
        pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), containerPrimaryKeyMapping)
        args = append(args, pkeyArgs...)
    }

    sql := fmt.Sprintf("UPDATE \"containers\" SET %s WHERE %s",
        strmangle.SetParamNames("\"", "\"", 1, colNames),
        strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, containerPrimaryKeyColumns, len(o)))

    if boil.DebugMode {
        fmt.Fprintln(boil.DebugWriter, sql)
        fmt.Fprintln(boil.DebugWriter, args...)
    }

    _, err := exec.Exec(sql, args...)
    if err != nil {
        return errors.Wrap(err, "kmodels: unable to update all in container slice")
    }

    return nil
}

// UpsertG attempts an insert, and does an update or ignore on conflict.
func (o *Container) UpsertG(updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
    return o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, whitelist...)
}

// UpsertGP attempts an insert, and does an update or ignore on conflict. Panics on error.
func (o *Container) UpsertGP(updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) {
    if err := o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, whitelist...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// UpsertP attempts an insert using an executor, and does an update or ignore on conflict.
// UpsertP panics on error.
func (o *Container) UpsertP(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) {
    if err := o.Upsert(exec, updateOnConflict, conflictColumns, updateColumns, whitelist...); err != nil {
        panic(boil.WrapErr(err))
    }
}

// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
func (o *Container) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
    if o == nil {
        return errors.New("kmodels: no containers provided for upsert")
    }
    currTime := time.Now().In(boil.GetLocation())

    if o.CreatedAt.Time.IsZero() {
        o.CreatedAt.Time = currTime
        o.CreatedAt.Valid = true
    }
    o.UpdatedAt.Time = currTime
    o.UpdatedAt.Valid = true

    nzDefaults := queries.NonZeroDefaultSet(containerColumnsWithDefault, o)

    // Build cache key in-line uglily - mysql vs postgres problems
    buf := strmangle.GetBuffer()

    if updateOnConflict {
        buf.WriteByte('t')
    } else {
        buf.WriteByte('f')
    }
    buf.WriteByte('.')
    for _, c := range conflictColumns {
        buf.WriteString(c)
    }
    buf.WriteByte('.')
    for _, c := range updateColumns {
        buf.WriteString(c)
    }
    buf.WriteByte('.')
    for _, c := range whitelist {
        buf.WriteString(c)
    }
    buf.WriteByte('.')
    for _, c := range nzDefaults {
        buf.WriteString(c)
    }
    key := buf.String()
    strmangle.PutBuffer(buf)

    containerUpsertCacheMut.RLock()
    cache, cached := containerUpsertCache[key]
    containerUpsertCacheMut.RUnlock()

    var err error

    if !cached {
        insert, ret := strmangle.InsertColumnSet(
            containerColumns,
            containerColumnsWithDefault,
            containerColumnsWithoutDefault,
            nzDefaults,
            whitelist,
        )

        update := strmangle.UpdateColumnSet(
            containerColumns,
            containerPrimaryKeyColumns,
            updateColumns,
        )
        if len(update) == 0 {
            return errors.New("kmodels: unable to upsert containers, could not build update column list")
        }

        conflict := conflictColumns
        if len(conflict) == 0 {
            conflict = make([]string, len(containerPrimaryKeyColumns))
            copy(conflict, containerPrimaryKeyColumns)
        }
        cache.query = queries.BuildUpsertQueryPostgres(dialect, "\"containers\"", updateOnConflict, ret, update, conflict, insert)

        cache.valueMapping, err = queries.BindMapping(containerType, containerMapping, insert)
        if err != nil {
            return err
        }
        if len(ret) != 0 {
            cache.retMapping, err = queries.BindMapping(containerType, containerMapping, ret)
            if err != nil {
                return err
            }
        }
    }

    value := reflect.Indirect(reflect.ValueOf(o))
    vals := queries.ValuesFromMapping(value, cache.valueMapping)
    var returns []interface{}
    if len(cache.retMapping) != 0 {
        returns = queries.PtrsFromMapping(value, cache.retMapping)
    }

    if boil.DebugMode {
        fmt.Fprintln(boil.DebugWriter, cache.query)
        fmt.Fprintln(boil.DebugWriter, vals)
    }

    if len(cache.retMapping) != 0 {
        err = exec.QueryRow(cache.query, vals...).Scan(returns...)
        if err == sql.ErrNoRows {
            err = nil // Postgres doesn't return anything when there's no update
        }
    } else {
        _, err = exec.Exec(cache.query, vals...)
    }
    if err != nil {
        return errors.Wrap(err, "kmodels: unable to upsert containers")
    }

    if !cached {
        containerUpsertCacheMut.Lock()
        containerUpsertCache[key] = cache
        containerUpsertCacheMut.Unlock()
    }

    return nil
}

// DeleteP deletes a single Container record with an executor.
// DeleteP will match against the primary key column to find the record to delete.
// Panics on error.
func (o *Container) DeleteP(exec boil.Executor) {
    if err := o.Delete(exec); err != nil {
        panic(boil.WrapErr(err))
    }
}

// DeleteG deletes a single Container record.
// DeleteG will match against the primary key column to find the record to delete.
func (o *Container) DeleteG() error {
    if o == nil {
        return errors.New("kmodels: no Container provided for deletion")
    }

    return o.Delete(boil.GetDB())
}

// DeleteGP deletes a single Container record.
// DeleteGP will match against the primary key column to find the record to delete.
// Panics on error.
func (o *Container) DeleteGP() {
    if err := o.DeleteG(); err != nil {
        panic(boil.WrapErr(err))
    }
}

// Delete deletes a single Container record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *Container) Delete(exec boil.Executor) error {
    if o == nil {
        return errors.New("kmodels: no Container provided for delete")
    }

    args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), containerPrimaryKeyMapping)
    sql := "DELETE FROM \"containers\" WHERE \"id\"=$1"

    if boil.DebugMode {
        fmt.Fprintln(boil.DebugWriter, sql)
        fmt.Fprintln(boil.DebugWriter, args...)
    }

    _, err := exec.Exec(sql, args...)
    if err != nil {
        return errors.Wrap(err, "kmodels: unable to delete from containers")
    }

    return nil
}

// DeleteAllP deletes all rows, and panics on error.
func (q containerQuery) DeleteAllP() {
    if err := q.DeleteAll(); err != nil {
        panic(boil.WrapErr(err))
    }
}

// DeleteAll deletes all matching rows.
func (q containerQuery) DeleteAll() error {
    if q.Query == nil {
        return errors.New("kmodels: no containerQuery provided for delete all")
    }

    queries.SetDelete(q.Query)

    _, err := q.Query.Exec()
    if err != nil {
        return errors.Wrap(err, "kmodels: unable to delete all from containers")
    }

    return nil
}

// DeleteAllGP deletes all rows in the slice, and panics on error.
func (o ContainerSlice) DeleteAllGP() {
    if err := o.DeleteAllG(); err != nil {
        panic(boil.WrapErr(err))
    }
}

// DeleteAllG deletes all rows in the slice.
func (o ContainerSlice) DeleteAllG() error {
    if o == nil {
        return errors.New("kmodels: no Container slice provided for delete all")
    }
    return o.DeleteAll(boil.GetDB())
}

// DeleteAllP deletes all rows in the slice, using an executor, and panics on error.
func (o ContainerSlice) DeleteAllP(exec boil.Executor) {
    if err := o.DeleteAll(exec); err != nil {
        panic(boil.WrapErr(err))
    }
}

// DeleteAll deletes all rows in the slice, using an executor.
func (o ContainerSlice) DeleteAll(exec boil.Executor) error {
    if o == nil {
        return errors.New("kmodels: no Container slice provided for delete all")
    }

    if len(o) == 0 {
        return nil
    }

    var args []interface{}
    for _, obj := range o {
        pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), containerPrimaryKeyMapping)
        args = append(args, pkeyArgs...)
    }

    sql := "DELETE FROM \"containers\" WHERE " +
        strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, containerPrimaryKeyColumns, len(o))

    if boil.DebugMode {
        fmt.Fprintln(boil.DebugWriter, sql)
        fmt.Fprintln(boil.DebugWriter, args)
    }

    _, err := exec.Exec(sql, args...)
    if err != nil {
        return errors.Wrap(err, "kmodels: unable to delete all from container slice")
    }

    return nil
}

// ReloadGP refetches the object from the database and panics on error.
func (o *Container) ReloadGP() {
    if err := o.ReloadG(); err != nil {
        panic(boil.WrapErr(err))
    }
}

// ReloadP refetches the object from the database with an executor. Panics on error.
func (o *Container) ReloadP(exec boil.Executor) {
    if err := o.Reload(exec); err != nil {
        panic(boil.WrapErr(err))
    }
}

// ReloadG refetches the object from the database using the primary keys.
func (o *Container) ReloadG() error {
    if o == nil {
        return errors.New("kmodels: no Container provided for reload")
    }

    return o.Reload(boil.GetDB())
}

// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *Container) Reload(exec boil.Executor) error {
    ret, err := FindContainer(exec, o.ID)
    if err != nil {
        return err
    }

    *o = *ret
    return nil
}

// ReloadAllGP refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
// Panics on error.
func (o *ContainerSlice) ReloadAllGP() {
    if err := o.ReloadAllG(); err != nil {
        panic(boil.WrapErr(err))
    }
}

// ReloadAllP refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
// Panics on error.
func (o *ContainerSlice) ReloadAllP(exec boil.Executor) {
    if err := o.ReloadAll(exec); err != nil {
        panic(boil.WrapErr(err))
    }
}

// ReloadAllG refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
func (o *ContainerSlice) ReloadAllG() error {
    if o == nil {
        return errors.New("kmodels: empty ContainerSlice provided for reload all")
    }

    return o.ReloadAll(boil.GetDB())
}

// ReloadAll refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
func (o *ContainerSlice) ReloadAll(exec boil.Executor) error {
    if o == nil || len(*o) == 0 {
        return nil
    }

    containers := ContainerSlice{}
    var args []interface{}
    for _, obj := range *o {
        pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), containerPrimaryKeyMapping)
        args = append(args, pkeyArgs...)
    }

    sql := "SELECT \"containers\".* FROM \"containers\" WHERE " +
        strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, containerPrimaryKeyColumns, len(*o))

    q := queries.Raw(exec, sql, args...)

    err := q.Bind(&containers)
    if err != nil {
        return errors.Wrap(err, "kmodels: unable to reload all in ContainerSlice")
    }

    *o = containers

    return nil
}

// ContainerExists checks if the Container row exists.
func ContainerExists(exec boil.Executor, id int) (bool, error) {
    var exists bool
    sql := "select exists(select 1 from \"containers\" where \"id\"=$1 limit 1)"

    if boil.DebugMode {
        fmt.Fprintln(boil.DebugWriter, sql)
        fmt.Fprintln(boil.DebugWriter, id)
    }

    row := exec.QueryRow(sql, id)

    err := row.Scan(&exists)
    if err != nil {
        return false, errors.Wrap(err, "kmodels: unable to check if containers exists")
    }

    return exists, nil
}

// ContainerExistsG checks if the Container row exists.
func ContainerExistsG(id int) (bool, error) {
    return ContainerExists(boil.GetDB(), id)
}

// ContainerExistsGP checks if the Container row exists. Panics on error.
func ContainerExistsGP(id int) bool {
    e, err := ContainerExists(boil.GetDB(), id)
    if err != nil {
        panic(boil.WrapErr(err))
    }

    return e
}

// ContainerExistsP checks if the Container row exists. Panics on error.
func ContainerExistsP(exec boil.Executor, id int) bool {
    e, err := ContainerExists(exec, id)
    if err != nil {
        panic(boil.WrapErr(err))
    }

    return e
}