nidus-sync/db/models/communication.bob.go
2026-05-04 19:07:29 +00:00

2829 lines
86 KiB
Go

// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/bob/expr"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// Communication is an object representing the database table.
type Communication struct {
Closed null.Val[time.Time] `db:"closed" `
ClosedBy null.Val[int32] `db:"closed_by" `
Created time.Time `db:"created" `
ID int32 `db:"id,pk" `
Invalidated null.Val[time.Time] `db:"invalidated" `
InvalidatedBy null.Val[int32] `db:"invalidated_by" `
Opened null.Val[time.Time] `db:"opened" `
OpenedBy null.Val[int32] `db:"opened_by" `
OrganizationID int32 `db:"organization_id" `
ResponseEmailLogID null.Val[int32] `db:"response_email_log_id" `
ResponseTextLogID null.Val[int32] `db:"response_text_log_id" `
SetPending null.Val[time.Time] `db:"set_pending" `
SetPendingBy null.Val[int32] `db:"set_pending_by" `
SourceEmailLogID null.Val[int32] `db:"source_email_log_id" `
SourceReportID null.Val[int32] `db:"source_report_id" `
SourceTextLogID null.Val[int32] `db:"source_text_log_id" `
SetPossibleIssue null.Val[time.Time] `db:"set_possible_issue" `
SetPossibleIssueBy null.Val[int32] `db:"set_possible_issue_by" `
SetPossibleResolved null.Val[time.Time] `db:"set_possible_resolved" `
SetPossibleResolvedBy null.Val[int32] `db:"set_possible_resolved_by" `
R communicationR `db:"-" `
}
// CommunicationSlice is an alias for a slice of pointers to Communication.
// This should almost always be used instead of []*Communication.
type CommunicationSlice []*Communication
// Communications contains methods to work with the communication table
var Communications = psql.NewTablex[*Communication, CommunicationSlice, *CommunicationSetter]("", "communication", buildCommunicationColumns("communication"))
// CommunicationsQuery is a query on the communication table
type CommunicationsQuery = *psql.ViewQuery[*Communication, CommunicationSlice]
// communicationR is where relationships are stored.
type communicationR struct {
ClosedByUser *User // communication.communication_closed_by_fkey
InvalidatedByUser *User // communication.communication_invalidated_by_fkey
OpenedByUser *User // communication.communication_opened_by_fkey
Organization *Organization // communication.communication_organization_id_fkey
ResponseEmailLogEmailLog *CommsEmailLog // communication.communication_response_email_log_id_fkey
ResponseTextLogTextLog *CommsTextLog // communication.communication_response_text_log_id_fkey
SetPendingByUser *User // communication.communication_set_pending_by_fkey
SetPossibleIssueByUser *User // communication.communication_set_possible_issue_by_fkey
SetPossibleResolvedByUser *User // communication.communication_set_possible_resolved_by_fkey
SourceEmailLogEmailLog *CommsEmailLog // communication.communication_source_email_log_id_fkey
SourceReportReport *PublicreportReport // communication.communication_source_report_id_fkey
SourceTextLogTextLog *CommsTextLog // communication.communication_source_text_log_id_fkey
}
func buildCommunicationColumns(alias string) communicationColumns {
return communicationColumns{
ColumnsExpr: expr.NewColumnsExpr(
"closed", "closed_by", "created", "id", "invalidated", "invalidated_by", "opened", "opened_by", "organization_id", "response_email_log_id", "response_text_log_id", "set_pending", "set_pending_by", "source_email_log_id", "source_report_id", "source_text_log_id", "set_possible_issue", "set_possible_issue_by", "set_possible_resolved", "set_possible_resolved_by",
).WithParent("communication"),
tableAlias: alias,
Closed: psql.Quote(alias, "closed"),
ClosedBy: psql.Quote(alias, "closed_by"),
Created: psql.Quote(alias, "created"),
ID: psql.Quote(alias, "id"),
Invalidated: psql.Quote(alias, "invalidated"),
InvalidatedBy: psql.Quote(alias, "invalidated_by"),
Opened: psql.Quote(alias, "opened"),
OpenedBy: psql.Quote(alias, "opened_by"),
OrganizationID: psql.Quote(alias, "organization_id"),
ResponseEmailLogID: psql.Quote(alias, "response_email_log_id"),
ResponseTextLogID: psql.Quote(alias, "response_text_log_id"),
SetPending: psql.Quote(alias, "set_pending"),
SetPendingBy: psql.Quote(alias, "set_pending_by"),
SourceEmailLogID: psql.Quote(alias, "source_email_log_id"),
SourceReportID: psql.Quote(alias, "source_report_id"),
SourceTextLogID: psql.Quote(alias, "source_text_log_id"),
SetPossibleIssue: psql.Quote(alias, "set_possible_issue"),
SetPossibleIssueBy: psql.Quote(alias, "set_possible_issue_by"),
SetPossibleResolved: psql.Quote(alias, "set_possible_resolved"),
SetPossibleResolvedBy: psql.Quote(alias, "set_possible_resolved_by"),
}
}
type communicationColumns struct {
expr.ColumnsExpr
tableAlias string
Closed psql.Expression
ClosedBy psql.Expression
Created psql.Expression
ID psql.Expression
Invalidated psql.Expression
InvalidatedBy psql.Expression
Opened psql.Expression
OpenedBy psql.Expression
OrganizationID psql.Expression
ResponseEmailLogID psql.Expression
ResponseTextLogID psql.Expression
SetPending psql.Expression
SetPendingBy psql.Expression
SourceEmailLogID psql.Expression
SourceReportID psql.Expression
SourceTextLogID psql.Expression
SetPossibleIssue psql.Expression
SetPossibleIssueBy psql.Expression
SetPossibleResolved psql.Expression
SetPossibleResolvedBy psql.Expression
}
func (c communicationColumns) Alias() string {
return c.tableAlias
}
func (communicationColumns) AliasedAs(alias string) communicationColumns {
return buildCommunicationColumns(alias)
}
// CommunicationSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type CommunicationSetter struct {
Closed omitnull.Val[time.Time] `db:"closed" `
ClosedBy omitnull.Val[int32] `db:"closed_by" `
Created omit.Val[time.Time] `db:"created" `
ID omit.Val[int32] `db:"id,pk" `
Invalidated omitnull.Val[time.Time] `db:"invalidated" `
InvalidatedBy omitnull.Val[int32] `db:"invalidated_by" `
Opened omitnull.Val[time.Time] `db:"opened" `
OpenedBy omitnull.Val[int32] `db:"opened_by" `
OrganizationID omit.Val[int32] `db:"organization_id" `
ResponseEmailLogID omitnull.Val[int32] `db:"response_email_log_id" `
ResponseTextLogID omitnull.Val[int32] `db:"response_text_log_id" `
SetPending omitnull.Val[time.Time] `db:"set_pending" `
SetPendingBy omitnull.Val[int32] `db:"set_pending_by" `
SourceEmailLogID omitnull.Val[int32] `db:"source_email_log_id" `
SourceReportID omitnull.Val[int32] `db:"source_report_id" `
SourceTextLogID omitnull.Val[int32] `db:"source_text_log_id" `
SetPossibleIssue omitnull.Val[time.Time] `db:"set_possible_issue" `
SetPossibleIssueBy omitnull.Val[int32] `db:"set_possible_issue_by" `
SetPossibleResolved omitnull.Val[time.Time] `db:"set_possible_resolved" `
SetPossibleResolvedBy omitnull.Val[int32] `db:"set_possible_resolved_by" `
}
func (s CommunicationSetter) SetColumns() []string {
vals := make([]string, 0, 20)
if !s.Closed.IsUnset() {
vals = append(vals, "closed")
}
if !s.ClosedBy.IsUnset() {
vals = append(vals, "closed_by")
}
if s.Created.IsValue() {
vals = append(vals, "created")
}
if s.ID.IsValue() {
vals = append(vals, "id")
}
if !s.Invalidated.IsUnset() {
vals = append(vals, "invalidated")
}
if !s.InvalidatedBy.IsUnset() {
vals = append(vals, "invalidated_by")
}
if !s.Opened.IsUnset() {
vals = append(vals, "opened")
}
if !s.OpenedBy.IsUnset() {
vals = append(vals, "opened_by")
}
if s.OrganizationID.IsValue() {
vals = append(vals, "organization_id")
}
if !s.ResponseEmailLogID.IsUnset() {
vals = append(vals, "response_email_log_id")
}
if !s.ResponseTextLogID.IsUnset() {
vals = append(vals, "response_text_log_id")
}
if !s.SetPending.IsUnset() {
vals = append(vals, "set_pending")
}
if !s.SetPendingBy.IsUnset() {
vals = append(vals, "set_pending_by")
}
if !s.SourceEmailLogID.IsUnset() {
vals = append(vals, "source_email_log_id")
}
if !s.SourceReportID.IsUnset() {
vals = append(vals, "source_report_id")
}
if !s.SourceTextLogID.IsUnset() {
vals = append(vals, "source_text_log_id")
}
if !s.SetPossibleIssue.IsUnset() {
vals = append(vals, "set_possible_issue")
}
if !s.SetPossibleIssueBy.IsUnset() {
vals = append(vals, "set_possible_issue_by")
}
if !s.SetPossibleResolved.IsUnset() {
vals = append(vals, "set_possible_resolved")
}
if !s.SetPossibleResolvedBy.IsUnset() {
vals = append(vals, "set_possible_resolved_by")
}
return vals
}
func (s CommunicationSetter) Overwrite(t *Communication) {
if !s.Closed.IsUnset() {
t.Closed = s.Closed.MustGetNull()
}
if !s.ClosedBy.IsUnset() {
t.ClosedBy = s.ClosedBy.MustGetNull()
}
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if s.ID.IsValue() {
t.ID = s.ID.MustGet()
}
if !s.Invalidated.IsUnset() {
t.Invalidated = s.Invalidated.MustGetNull()
}
if !s.InvalidatedBy.IsUnset() {
t.InvalidatedBy = s.InvalidatedBy.MustGetNull()
}
if !s.Opened.IsUnset() {
t.Opened = s.Opened.MustGetNull()
}
if !s.OpenedBy.IsUnset() {
t.OpenedBy = s.OpenedBy.MustGetNull()
}
if s.OrganizationID.IsValue() {
t.OrganizationID = s.OrganizationID.MustGet()
}
if !s.ResponseEmailLogID.IsUnset() {
t.ResponseEmailLogID = s.ResponseEmailLogID.MustGetNull()
}
if !s.ResponseTextLogID.IsUnset() {
t.ResponseTextLogID = s.ResponseTextLogID.MustGetNull()
}
if !s.SetPending.IsUnset() {
t.SetPending = s.SetPending.MustGetNull()
}
if !s.SetPendingBy.IsUnset() {
t.SetPendingBy = s.SetPendingBy.MustGetNull()
}
if !s.SourceEmailLogID.IsUnset() {
t.SourceEmailLogID = s.SourceEmailLogID.MustGetNull()
}
if !s.SourceReportID.IsUnset() {
t.SourceReportID = s.SourceReportID.MustGetNull()
}
if !s.SourceTextLogID.IsUnset() {
t.SourceTextLogID = s.SourceTextLogID.MustGetNull()
}
if !s.SetPossibleIssue.IsUnset() {
t.SetPossibleIssue = s.SetPossibleIssue.MustGetNull()
}
if !s.SetPossibleIssueBy.IsUnset() {
t.SetPossibleIssueBy = s.SetPossibleIssueBy.MustGetNull()
}
if !s.SetPossibleResolved.IsUnset() {
t.SetPossibleResolved = s.SetPossibleResolved.MustGetNull()
}
if !s.SetPossibleResolvedBy.IsUnset() {
t.SetPossibleResolvedBy = s.SetPossibleResolvedBy.MustGetNull()
}
}
func (s *CommunicationSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return Communications.BeforeInsertHooks.RunHooks(ctx, exec, s)
})
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 20)
if !s.Closed.IsUnset() {
vals[0] = psql.Arg(s.Closed.MustGetNull())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if !s.ClosedBy.IsUnset() {
vals[1] = psql.Arg(s.ClosedBy.MustGetNull())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.Created.IsValue() {
vals[2] = psql.Arg(s.Created.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if s.ID.IsValue() {
vals[3] = psql.Arg(s.ID.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
if !s.Invalidated.IsUnset() {
vals[4] = psql.Arg(s.Invalidated.MustGetNull())
} else {
vals[4] = psql.Raw("DEFAULT")
}
if !s.InvalidatedBy.IsUnset() {
vals[5] = psql.Arg(s.InvalidatedBy.MustGetNull())
} else {
vals[5] = psql.Raw("DEFAULT")
}
if !s.Opened.IsUnset() {
vals[6] = psql.Arg(s.Opened.MustGetNull())
} else {
vals[6] = psql.Raw("DEFAULT")
}
if !s.OpenedBy.IsUnset() {
vals[7] = psql.Arg(s.OpenedBy.MustGetNull())
} else {
vals[7] = psql.Raw("DEFAULT")
}
if s.OrganizationID.IsValue() {
vals[8] = psql.Arg(s.OrganizationID.MustGet())
} else {
vals[8] = psql.Raw("DEFAULT")
}
if !s.ResponseEmailLogID.IsUnset() {
vals[9] = psql.Arg(s.ResponseEmailLogID.MustGetNull())
} else {
vals[9] = psql.Raw("DEFAULT")
}
if !s.ResponseTextLogID.IsUnset() {
vals[10] = psql.Arg(s.ResponseTextLogID.MustGetNull())
} else {
vals[10] = psql.Raw("DEFAULT")
}
if !s.SetPending.IsUnset() {
vals[11] = psql.Arg(s.SetPending.MustGetNull())
} else {
vals[11] = psql.Raw("DEFAULT")
}
if !s.SetPendingBy.IsUnset() {
vals[12] = psql.Arg(s.SetPendingBy.MustGetNull())
} else {
vals[12] = psql.Raw("DEFAULT")
}
if !s.SourceEmailLogID.IsUnset() {
vals[13] = psql.Arg(s.SourceEmailLogID.MustGetNull())
} else {
vals[13] = psql.Raw("DEFAULT")
}
if !s.SourceReportID.IsUnset() {
vals[14] = psql.Arg(s.SourceReportID.MustGetNull())
} else {
vals[14] = psql.Raw("DEFAULT")
}
if !s.SourceTextLogID.IsUnset() {
vals[15] = psql.Arg(s.SourceTextLogID.MustGetNull())
} else {
vals[15] = psql.Raw("DEFAULT")
}
if !s.SetPossibleIssue.IsUnset() {
vals[16] = psql.Arg(s.SetPossibleIssue.MustGetNull())
} else {
vals[16] = psql.Raw("DEFAULT")
}
if !s.SetPossibleIssueBy.IsUnset() {
vals[17] = psql.Arg(s.SetPossibleIssueBy.MustGetNull())
} else {
vals[17] = psql.Raw("DEFAULT")
}
if !s.SetPossibleResolved.IsUnset() {
vals[18] = psql.Arg(s.SetPossibleResolved.MustGetNull())
} else {
vals[18] = psql.Raw("DEFAULT")
}
if !s.SetPossibleResolvedBy.IsUnset() {
vals[19] = psql.Arg(s.SetPossibleResolvedBy.MustGetNull())
} else {
vals[19] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s CommunicationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s CommunicationSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 20)
if !s.Closed.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "closed")...),
psql.Arg(s.Closed),
}})
}
if !s.ClosedBy.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "closed_by")...),
psql.Arg(s.ClosedBy),
}})
}
if s.Created.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "created")...),
psql.Arg(s.Created),
}})
}
if s.ID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "id")...),
psql.Arg(s.ID),
}})
}
if !s.Invalidated.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "invalidated")...),
psql.Arg(s.Invalidated),
}})
}
if !s.InvalidatedBy.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "invalidated_by")...),
psql.Arg(s.InvalidatedBy),
}})
}
if !s.Opened.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "opened")...),
psql.Arg(s.Opened),
}})
}
if !s.OpenedBy.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "opened_by")...),
psql.Arg(s.OpenedBy),
}})
}
if s.OrganizationID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "organization_id")...),
psql.Arg(s.OrganizationID),
}})
}
if !s.ResponseEmailLogID.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "response_email_log_id")...),
psql.Arg(s.ResponseEmailLogID),
}})
}
if !s.ResponseTextLogID.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "response_text_log_id")...),
psql.Arg(s.ResponseTextLogID),
}})
}
if !s.SetPending.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "set_pending")...),
psql.Arg(s.SetPending),
}})
}
if !s.SetPendingBy.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "set_pending_by")...),
psql.Arg(s.SetPendingBy),
}})
}
if !s.SourceEmailLogID.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "source_email_log_id")...),
psql.Arg(s.SourceEmailLogID),
}})
}
if !s.SourceReportID.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "source_report_id")...),
psql.Arg(s.SourceReportID),
}})
}
if !s.SourceTextLogID.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "source_text_log_id")...),
psql.Arg(s.SourceTextLogID),
}})
}
if !s.SetPossibleIssue.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "set_possible_issue")...),
psql.Arg(s.SetPossibleIssue),
}})
}
if !s.SetPossibleIssueBy.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "set_possible_issue_by")...),
psql.Arg(s.SetPossibleIssueBy),
}})
}
if !s.SetPossibleResolved.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "set_possible_resolved")...),
psql.Arg(s.SetPossibleResolved),
}})
}
if !s.SetPossibleResolvedBy.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "set_possible_resolved_by")...),
psql.Arg(s.SetPossibleResolvedBy),
}})
}
return exprs
}
// FindCommunication retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindCommunication(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*Communication, error) {
if len(cols) == 0 {
return Communications.Query(
sm.Where(Communications.Columns.ID.EQ(psql.Arg(IDPK))),
).One(ctx, exec)
}
return Communications.Query(
sm.Where(Communications.Columns.ID.EQ(psql.Arg(IDPK))),
sm.Columns(Communications.Columns.Only(cols...)),
).One(ctx, exec)
}
// CommunicationExists checks the presence of a single record by primary key
func CommunicationExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
return Communications.Query(
sm.Where(Communications.Columns.ID.EQ(psql.Arg(IDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after Communication is retrieved from the database
func (o *Communication) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = Communications.AfterSelectHooks.RunHooks(ctx, exec, CommunicationSlice{o})
case bob.QueryTypeInsert:
ctx, err = Communications.AfterInsertHooks.RunHooks(ctx, exec, CommunicationSlice{o})
case bob.QueryTypeUpdate:
ctx, err = Communications.AfterUpdateHooks.RunHooks(ctx, exec, CommunicationSlice{o})
case bob.QueryTypeDelete:
ctx, err = Communications.AfterDeleteHooks.RunHooks(ctx, exec, CommunicationSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the Communication
func (o *Communication) primaryKeyVals() bob.Expression {
return psql.Arg(o.ID)
}
func (o *Communication) pkEQ() dialect.Expression {
return psql.Quote("communication", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the Communication
func (o *Communication) Update(ctx context.Context, exec bob.Executor, s *CommunicationSetter) error {
v, err := Communications.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
if err != nil {
return err
}
o.R = v.R
*o = *v
return nil
}
// Delete deletes a single Communication record with an executor
func (o *Communication) Delete(ctx context.Context, exec bob.Executor) error {
_, err := Communications.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the Communication using the executor
func (o *Communication) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := Communications.Query(
sm.Where(Communications.Columns.ID.EQ(psql.Arg(o.ID))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after CommunicationSlice is retrieved from the database
func (o CommunicationSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = Communications.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = Communications.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = Communications.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = Communications.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o CommunicationSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Quote("communication", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o CommunicationSlice) copyMatchingRows(from ...*Communication) {
for i, old := range o {
for _, new := range from {
if new.ID != old.ID {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o CommunicationSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return Communications.BeforeUpdateHooks.RunHooks(ctx, exec, o)
})
q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
var err error
switch retrieved := retrieved.(type) {
case *Communication:
o.copyMatchingRows(retrieved)
case []*Communication:
o.copyMatchingRows(retrieved...)
case CommunicationSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a Communication or a slice of Communication
// then run the AfterUpdateHooks on the slice
_, err = Communications.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o CommunicationSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return Communications.BeforeDeleteHooks.RunHooks(ctx, exec, o)
})
q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
var err error
switch retrieved := retrieved.(type) {
case *Communication:
o.copyMatchingRows(retrieved)
case []*Communication:
o.copyMatchingRows(retrieved...)
case CommunicationSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a Communication or a slice of Communication
// then run the AfterDeleteHooks on the slice
_, err = Communications.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o CommunicationSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals CommunicationSetter) error {
if len(o) == 0 {
return nil
}
_, err := Communications.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o CommunicationSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := Communications.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o CommunicationSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := Communications.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// ClosedByUser starts a query for related objects on user_
func (o *Communication) ClosedByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.ClosedBy))),
)...)
}
func (os CommunicationSlice) ClosedByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkClosedBy := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkClosedBy = append(pkClosedBy, o.ClosedBy)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkClosedBy), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// InvalidatedByUser starts a query for related objects on user_
func (o *Communication) InvalidatedByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.InvalidatedBy))),
)...)
}
func (os CommunicationSlice) InvalidatedByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkInvalidatedBy := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkInvalidatedBy = append(pkInvalidatedBy, o.InvalidatedBy)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkInvalidatedBy), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// OpenedByUser starts a query for related objects on user_
func (o *Communication) OpenedByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.OpenedBy))),
)...)
}
func (os CommunicationSlice) OpenedByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkOpenedBy := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkOpenedBy = append(pkOpenedBy, o.OpenedBy)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkOpenedBy), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// Organization starts a query for related objects on organization
func (o *Communication) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
return Organizations.Query(append(mods,
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
)...)
}
func (os CommunicationSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
pkOrganizationID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkOrganizationID = append(pkOrganizationID, o.OrganizationID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")),
))
return Organizations.Query(append(mods,
sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// ResponseEmailLogEmailLog starts a query for related objects on comms.email_log
func (o *Communication) ResponseEmailLogEmailLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailLogsQuery {
return CommsEmailLogs.Query(append(mods,
sm.Where(CommsEmailLogs.Columns.ID.EQ(psql.Arg(o.ResponseEmailLogID))),
)...)
}
func (os CommunicationSlice) ResponseEmailLogEmailLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailLogsQuery {
pkResponseEmailLogID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkResponseEmailLogID = append(pkResponseEmailLogID, o.ResponseEmailLogID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkResponseEmailLogID), "integer[]")),
))
return CommsEmailLogs.Query(append(mods,
sm.Where(psql.Group(CommsEmailLogs.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// ResponseTextLogTextLog starts a query for related objects on comms.text_log
func (o *Communication) ResponseTextLogTextLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
return CommsTextLogs.Query(append(mods,
sm.Where(CommsTextLogs.Columns.ID.EQ(psql.Arg(o.ResponseTextLogID))),
)...)
}
func (os CommunicationSlice) ResponseTextLogTextLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
pkResponseTextLogID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkResponseTextLogID = append(pkResponseTextLogID, o.ResponseTextLogID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkResponseTextLogID), "integer[]")),
))
return CommsTextLogs.Query(append(mods,
sm.Where(psql.Group(CommsTextLogs.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// SetPendingByUser starts a query for related objects on user_
func (o *Communication) SetPendingByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.SetPendingBy))),
)...)
}
func (os CommunicationSlice) SetPendingByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkSetPendingBy := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkSetPendingBy = append(pkSetPendingBy, o.SetPendingBy)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkSetPendingBy), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// SetPossibleIssueByUser starts a query for related objects on user_
func (o *Communication) SetPossibleIssueByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.SetPossibleIssueBy))),
)...)
}
func (os CommunicationSlice) SetPossibleIssueByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkSetPossibleIssueBy := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkSetPossibleIssueBy = append(pkSetPossibleIssueBy, o.SetPossibleIssueBy)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkSetPossibleIssueBy), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// SetPossibleResolvedByUser starts a query for related objects on user_
func (o *Communication) SetPossibleResolvedByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.SetPossibleResolvedBy))),
)...)
}
func (os CommunicationSlice) SetPossibleResolvedByUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkSetPossibleResolvedBy := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkSetPossibleResolvedBy = append(pkSetPossibleResolvedBy, o.SetPossibleResolvedBy)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkSetPossibleResolvedBy), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// SourceEmailLogEmailLog starts a query for related objects on comms.email_log
func (o *Communication) SourceEmailLogEmailLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailLogsQuery {
return CommsEmailLogs.Query(append(mods,
sm.Where(CommsEmailLogs.Columns.ID.EQ(psql.Arg(o.SourceEmailLogID))),
)...)
}
func (os CommunicationSlice) SourceEmailLogEmailLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailLogsQuery {
pkSourceEmailLogID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkSourceEmailLogID = append(pkSourceEmailLogID, o.SourceEmailLogID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkSourceEmailLogID), "integer[]")),
))
return CommsEmailLogs.Query(append(mods,
sm.Where(psql.Group(CommsEmailLogs.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// SourceReportReport starts a query for related objects on publicreport.report
func (o *Communication) SourceReportReport(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
return PublicreportReports.Query(append(mods,
sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(o.SourceReportID))),
)...)
}
func (os CommunicationSlice) SourceReportReport(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
pkSourceReportID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkSourceReportID = append(pkSourceReportID, o.SourceReportID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkSourceReportID), "integer[]")),
))
return PublicreportReports.Query(append(mods,
sm.Where(psql.Group(PublicreportReports.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// SourceTextLogTextLog starts a query for related objects on comms.text_log
func (o *Communication) SourceTextLogTextLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
return CommsTextLogs.Query(append(mods,
sm.Where(CommsTextLogs.Columns.ID.EQ(psql.Arg(o.SourceTextLogID))),
)...)
}
func (os CommunicationSlice) SourceTextLogTextLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
pkSourceTextLogID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkSourceTextLogID = append(pkSourceTextLogID, o.SourceTextLogID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkSourceTextLogID), "integer[]")),
))
return CommsTextLogs.Query(append(mods,
sm.Where(psql.Group(CommsTextLogs.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachCommunicationClosedByUser0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, user1 *User) (*Communication, error) {
setter := &CommunicationSetter{
ClosedBy: omitnull.From(user1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationClosedByUser0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertClosedByUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationClosedByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.ClosedByUser = user1
user1.R.ClosedByCommunications = append(user1.R.ClosedByCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachClosedByUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachCommunicationClosedByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.ClosedByUser = user1
user1.R.ClosedByCommunications = append(user1.R.ClosedByCommunications, communication0)
return nil
}
func attachCommunicationInvalidatedByUser0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, user1 *User) (*Communication, error) {
setter := &CommunicationSetter{
InvalidatedBy: omitnull.From(user1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationInvalidatedByUser0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertInvalidatedByUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationInvalidatedByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.InvalidatedByUser = user1
user1.R.InvalidatedByCommunications = append(user1.R.InvalidatedByCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachInvalidatedByUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachCommunicationInvalidatedByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.InvalidatedByUser = user1
user1.R.InvalidatedByCommunications = append(user1.R.InvalidatedByCommunications, communication0)
return nil
}
func attachCommunicationOpenedByUser0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, user1 *User) (*Communication, error) {
setter := &CommunicationSetter{
OpenedBy: omitnull.From(user1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationOpenedByUser0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertOpenedByUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationOpenedByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.OpenedByUser = user1
user1.R.OpenedByCommunications = append(user1.R.OpenedByCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachOpenedByUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachCommunicationOpenedByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.OpenedByUser = user1
user1.R.OpenedByCommunications = append(user1.R.OpenedByCommunications, communication0)
return nil
}
func attachCommunicationOrganization0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, organization1 *Organization) (*Communication, error) {
setter := &CommunicationSetter{
OrganizationID: omit.From(organization1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationOrganization0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
var err error
organization1, err := Organizations.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationOrganization0(ctx, exec, 1, communication0, organization1)
if err != nil {
return err
}
communication0.R.Organization = organization1
organization1.R.Communications = append(organization1.R.Communications, communication0)
return nil
}
func (communication0 *Communication) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
var err error
_, err = attachCommunicationOrganization0(ctx, exec, 1, communication0, organization1)
if err != nil {
return err
}
communication0.R.Organization = organization1
organization1.R.Communications = append(organization1.R.Communications, communication0)
return nil
}
func attachCommunicationResponseEmailLogEmailLog0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, commsEmailLog1 *CommsEmailLog) (*Communication, error) {
setter := &CommunicationSetter{
ResponseEmailLogID: omitnull.From(commsEmailLog1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationResponseEmailLogEmailLog0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertResponseEmailLogEmailLog(ctx context.Context, exec bob.Executor, related *CommsEmailLogSetter) error {
var err error
commsEmailLog1, err := CommsEmailLogs.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationResponseEmailLogEmailLog0(ctx, exec, 1, communication0, commsEmailLog1)
if err != nil {
return err
}
communication0.R.ResponseEmailLogEmailLog = commsEmailLog1
commsEmailLog1.R.ResponseEmailLogCommunications = append(commsEmailLog1.R.ResponseEmailLogCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachResponseEmailLogEmailLog(ctx context.Context, exec bob.Executor, commsEmailLog1 *CommsEmailLog) error {
var err error
_, err = attachCommunicationResponseEmailLogEmailLog0(ctx, exec, 1, communication0, commsEmailLog1)
if err != nil {
return err
}
communication0.R.ResponseEmailLogEmailLog = commsEmailLog1
commsEmailLog1.R.ResponseEmailLogCommunications = append(commsEmailLog1.R.ResponseEmailLogCommunications, communication0)
return nil
}
func attachCommunicationResponseTextLogTextLog0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, commsTextLog1 *CommsTextLog) (*Communication, error) {
setter := &CommunicationSetter{
ResponseTextLogID: omitnull.From(commsTextLog1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationResponseTextLogTextLog0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertResponseTextLogTextLog(ctx context.Context, exec bob.Executor, related *CommsTextLogSetter) error {
var err error
commsTextLog1, err := CommsTextLogs.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationResponseTextLogTextLog0(ctx, exec, 1, communication0, commsTextLog1)
if err != nil {
return err
}
communication0.R.ResponseTextLogTextLog = commsTextLog1
commsTextLog1.R.ResponseTextLogCommunications = append(commsTextLog1.R.ResponseTextLogCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachResponseTextLogTextLog(ctx context.Context, exec bob.Executor, commsTextLog1 *CommsTextLog) error {
var err error
_, err = attachCommunicationResponseTextLogTextLog0(ctx, exec, 1, communication0, commsTextLog1)
if err != nil {
return err
}
communication0.R.ResponseTextLogTextLog = commsTextLog1
commsTextLog1.R.ResponseTextLogCommunications = append(commsTextLog1.R.ResponseTextLogCommunications, communication0)
return nil
}
func attachCommunicationSetPendingByUser0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, user1 *User) (*Communication, error) {
setter := &CommunicationSetter{
SetPendingBy: omitnull.From(user1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationSetPendingByUser0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertSetPendingByUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationSetPendingByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.SetPendingByUser = user1
user1.R.SetPendingByCommunications = append(user1.R.SetPendingByCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachSetPendingByUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachCommunicationSetPendingByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.SetPendingByUser = user1
user1.R.SetPendingByCommunications = append(user1.R.SetPendingByCommunications, communication0)
return nil
}
func attachCommunicationSetPossibleIssueByUser0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, user1 *User) (*Communication, error) {
setter := &CommunicationSetter{
SetPossibleIssueBy: omitnull.From(user1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationSetPossibleIssueByUser0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertSetPossibleIssueByUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationSetPossibleIssueByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.SetPossibleIssueByUser = user1
user1.R.SetPossibleIssueByCommunications = append(user1.R.SetPossibleIssueByCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachSetPossibleIssueByUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachCommunicationSetPossibleIssueByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.SetPossibleIssueByUser = user1
user1.R.SetPossibleIssueByCommunications = append(user1.R.SetPossibleIssueByCommunications, communication0)
return nil
}
func attachCommunicationSetPossibleResolvedByUser0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, user1 *User) (*Communication, error) {
setter := &CommunicationSetter{
SetPossibleResolvedBy: omitnull.From(user1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationSetPossibleResolvedByUser0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertSetPossibleResolvedByUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationSetPossibleResolvedByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.SetPossibleResolvedByUser = user1
user1.R.SetPossibleResolvedByCommunications = append(user1.R.SetPossibleResolvedByCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachSetPossibleResolvedByUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachCommunicationSetPossibleResolvedByUser0(ctx, exec, 1, communication0, user1)
if err != nil {
return err
}
communication0.R.SetPossibleResolvedByUser = user1
user1.R.SetPossibleResolvedByCommunications = append(user1.R.SetPossibleResolvedByCommunications, communication0)
return nil
}
func attachCommunicationSourceEmailLogEmailLog0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, commsEmailLog1 *CommsEmailLog) (*Communication, error) {
setter := &CommunicationSetter{
SourceEmailLogID: omitnull.From(commsEmailLog1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationSourceEmailLogEmailLog0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertSourceEmailLogEmailLog(ctx context.Context, exec bob.Executor, related *CommsEmailLogSetter) error {
var err error
commsEmailLog1, err := CommsEmailLogs.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationSourceEmailLogEmailLog0(ctx, exec, 1, communication0, commsEmailLog1)
if err != nil {
return err
}
communication0.R.SourceEmailLogEmailLog = commsEmailLog1
commsEmailLog1.R.SourceEmailLogCommunications = append(commsEmailLog1.R.SourceEmailLogCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachSourceEmailLogEmailLog(ctx context.Context, exec bob.Executor, commsEmailLog1 *CommsEmailLog) error {
var err error
_, err = attachCommunicationSourceEmailLogEmailLog0(ctx, exec, 1, communication0, commsEmailLog1)
if err != nil {
return err
}
communication0.R.SourceEmailLogEmailLog = commsEmailLog1
commsEmailLog1.R.SourceEmailLogCommunications = append(commsEmailLog1.R.SourceEmailLogCommunications, communication0)
return nil
}
func attachCommunicationSourceReportReport0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, publicreportReport1 *PublicreportReport) (*Communication, error) {
setter := &CommunicationSetter{
SourceReportID: omitnull.From(publicreportReport1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationSourceReportReport0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertSourceReportReport(ctx context.Context, exec bob.Executor, related *PublicreportReportSetter) error {
var err error
publicreportReport1, err := PublicreportReports.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationSourceReportReport0(ctx, exec, 1, communication0, publicreportReport1)
if err != nil {
return err
}
communication0.R.SourceReportReport = publicreportReport1
publicreportReport1.R.SourceReportCommunications = append(publicreportReport1.R.SourceReportCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachSourceReportReport(ctx context.Context, exec bob.Executor, publicreportReport1 *PublicreportReport) error {
var err error
_, err = attachCommunicationSourceReportReport0(ctx, exec, 1, communication0, publicreportReport1)
if err != nil {
return err
}
communication0.R.SourceReportReport = publicreportReport1
publicreportReport1.R.SourceReportCommunications = append(publicreportReport1.R.SourceReportCommunications, communication0)
return nil
}
func attachCommunicationSourceTextLogTextLog0(ctx context.Context, exec bob.Executor, count int, communication0 *Communication, commsTextLog1 *CommsTextLog) (*Communication, error) {
setter := &CommunicationSetter{
SourceTextLogID: omitnull.From(commsTextLog1.ID),
}
err := communication0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommunicationSourceTextLogTextLog0: %w", err)
}
return communication0, nil
}
func (communication0 *Communication) InsertSourceTextLogTextLog(ctx context.Context, exec bob.Executor, related *CommsTextLogSetter) error {
var err error
commsTextLog1, err := CommsTextLogs.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommunicationSourceTextLogTextLog0(ctx, exec, 1, communication0, commsTextLog1)
if err != nil {
return err
}
communication0.R.SourceTextLogTextLog = commsTextLog1
commsTextLog1.R.SourceTextLogCommunications = append(commsTextLog1.R.SourceTextLogCommunications, communication0)
return nil
}
func (communication0 *Communication) AttachSourceTextLogTextLog(ctx context.Context, exec bob.Executor, commsTextLog1 *CommsTextLog) error {
var err error
_, err = attachCommunicationSourceTextLogTextLog0(ctx, exec, 1, communication0, commsTextLog1)
if err != nil {
return err
}
communication0.R.SourceTextLogTextLog = commsTextLog1
commsTextLog1.R.SourceTextLogCommunications = append(commsTextLog1.R.SourceTextLogCommunications, communication0)
return nil
}
type communicationWhere[Q psql.Filterable] struct {
Closed psql.WhereNullMod[Q, time.Time]
ClosedBy psql.WhereNullMod[Q, int32]
Created psql.WhereMod[Q, time.Time]
ID psql.WhereMod[Q, int32]
Invalidated psql.WhereNullMod[Q, time.Time]
InvalidatedBy psql.WhereNullMod[Q, int32]
Opened psql.WhereNullMod[Q, time.Time]
OpenedBy psql.WhereNullMod[Q, int32]
OrganizationID psql.WhereMod[Q, int32]
ResponseEmailLogID psql.WhereNullMod[Q, int32]
ResponseTextLogID psql.WhereNullMod[Q, int32]
SetPending psql.WhereNullMod[Q, time.Time]
SetPendingBy psql.WhereNullMod[Q, int32]
SourceEmailLogID psql.WhereNullMod[Q, int32]
SourceReportID psql.WhereNullMod[Q, int32]
SourceTextLogID psql.WhereNullMod[Q, int32]
SetPossibleIssue psql.WhereNullMod[Q, time.Time]
SetPossibleIssueBy psql.WhereNullMod[Q, int32]
SetPossibleResolved psql.WhereNullMod[Q, time.Time]
SetPossibleResolvedBy psql.WhereNullMod[Q, int32]
}
func (communicationWhere[Q]) AliasedAs(alias string) communicationWhere[Q] {
return buildCommunicationWhere[Q](buildCommunicationColumns(alias))
}
func buildCommunicationWhere[Q psql.Filterable](cols communicationColumns) communicationWhere[Q] {
return communicationWhere[Q]{
Closed: psql.WhereNull[Q, time.Time](cols.Closed),
ClosedBy: psql.WhereNull[Q, int32](cols.ClosedBy),
Created: psql.Where[Q, time.Time](cols.Created),
ID: psql.Where[Q, int32](cols.ID),
Invalidated: psql.WhereNull[Q, time.Time](cols.Invalidated),
InvalidatedBy: psql.WhereNull[Q, int32](cols.InvalidatedBy),
Opened: psql.WhereNull[Q, time.Time](cols.Opened),
OpenedBy: psql.WhereNull[Q, int32](cols.OpenedBy),
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
ResponseEmailLogID: psql.WhereNull[Q, int32](cols.ResponseEmailLogID),
ResponseTextLogID: psql.WhereNull[Q, int32](cols.ResponseTextLogID),
SetPending: psql.WhereNull[Q, time.Time](cols.SetPending),
SetPendingBy: psql.WhereNull[Q, int32](cols.SetPendingBy),
SourceEmailLogID: psql.WhereNull[Q, int32](cols.SourceEmailLogID),
SourceReportID: psql.WhereNull[Q, int32](cols.SourceReportID),
SourceTextLogID: psql.WhereNull[Q, int32](cols.SourceTextLogID),
SetPossibleIssue: psql.WhereNull[Q, time.Time](cols.SetPossibleIssue),
SetPossibleIssueBy: psql.WhereNull[Q, int32](cols.SetPossibleIssueBy),
SetPossibleResolved: psql.WhereNull[Q, time.Time](cols.SetPossibleResolved),
SetPossibleResolvedBy: psql.WhereNull[Q, int32](cols.SetPossibleResolvedBy),
}
}
func (o *Communication) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "ClosedByUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.ClosedByUser = rel
if rel != nil {
rel.R.ClosedByCommunications = CommunicationSlice{o}
}
return nil
case "InvalidatedByUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.InvalidatedByUser = rel
if rel != nil {
rel.R.InvalidatedByCommunications = CommunicationSlice{o}
}
return nil
case "OpenedByUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.OpenedByUser = rel
if rel != nil {
rel.R.OpenedByCommunications = CommunicationSlice{o}
}
return nil
case "Organization":
rel, ok := retrieved.(*Organization)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.Organization = rel
if rel != nil {
rel.R.Communications = CommunicationSlice{o}
}
return nil
case "ResponseEmailLogEmailLog":
rel, ok := retrieved.(*CommsEmailLog)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.ResponseEmailLogEmailLog = rel
if rel != nil {
rel.R.ResponseEmailLogCommunications = CommunicationSlice{o}
}
return nil
case "ResponseTextLogTextLog":
rel, ok := retrieved.(*CommsTextLog)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.ResponseTextLogTextLog = rel
if rel != nil {
rel.R.ResponseTextLogCommunications = CommunicationSlice{o}
}
return nil
case "SetPendingByUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.SetPendingByUser = rel
if rel != nil {
rel.R.SetPendingByCommunications = CommunicationSlice{o}
}
return nil
case "SetPossibleIssueByUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.SetPossibleIssueByUser = rel
if rel != nil {
rel.R.SetPossibleIssueByCommunications = CommunicationSlice{o}
}
return nil
case "SetPossibleResolvedByUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.SetPossibleResolvedByUser = rel
if rel != nil {
rel.R.SetPossibleResolvedByCommunications = CommunicationSlice{o}
}
return nil
case "SourceEmailLogEmailLog":
rel, ok := retrieved.(*CommsEmailLog)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.SourceEmailLogEmailLog = rel
if rel != nil {
rel.R.SourceEmailLogCommunications = CommunicationSlice{o}
}
return nil
case "SourceReportReport":
rel, ok := retrieved.(*PublicreportReport)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.SourceReportReport = rel
if rel != nil {
rel.R.SourceReportCommunications = CommunicationSlice{o}
}
return nil
case "SourceTextLogTextLog":
rel, ok := retrieved.(*CommsTextLog)
if !ok {
return fmt.Errorf("communication cannot load %T as %q", retrieved, name)
}
o.R.SourceTextLogTextLog = rel
if rel != nil {
rel.R.SourceTextLogCommunications = CommunicationSlice{o}
}
return nil
default:
return fmt.Errorf("communication has no relationship %q", name)
}
}
type communicationPreloader struct {
ClosedByUser func(...psql.PreloadOption) psql.Preloader
InvalidatedByUser func(...psql.PreloadOption) psql.Preloader
OpenedByUser func(...psql.PreloadOption) psql.Preloader
Organization func(...psql.PreloadOption) psql.Preloader
ResponseEmailLogEmailLog func(...psql.PreloadOption) psql.Preloader
ResponseTextLogTextLog func(...psql.PreloadOption) psql.Preloader
SetPendingByUser func(...psql.PreloadOption) psql.Preloader
SetPossibleIssueByUser func(...psql.PreloadOption) psql.Preloader
SetPossibleResolvedByUser func(...psql.PreloadOption) psql.Preloader
SourceEmailLogEmailLog func(...psql.PreloadOption) psql.Preloader
SourceReportReport func(...psql.PreloadOption) psql.Preloader
SourceTextLogTextLog func(...psql.PreloadOption) psql.Preloader
}
func buildCommunicationPreloader() communicationPreloader {
return communicationPreloader{
ClosedByUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "ClosedByUser",
Sides: []psql.PreloadSide{
{
From: Communications,
To: Users,
FromColumns: []string{"closed_by"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
InvalidatedByUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "InvalidatedByUser",
Sides: []psql.PreloadSide{
{
From: Communications,
To: Users,
FromColumns: []string{"invalidated_by"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
OpenedByUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "OpenedByUser",
Sides: []psql.PreloadSide{
{
From: Communications,
To: Users,
FromColumns: []string{"opened_by"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
Name: "Organization",
Sides: []psql.PreloadSide{
{
From: Communications,
To: Organizations,
FromColumns: []string{"organization_id"},
ToColumns: []string{"id"},
},
},
}, Organizations.Columns.Names(), opts...)
},
ResponseEmailLogEmailLog: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsEmailLog, CommsEmailLogSlice](psql.PreloadRel{
Name: "ResponseEmailLogEmailLog",
Sides: []psql.PreloadSide{
{
From: Communications,
To: CommsEmailLogs,
FromColumns: []string{"response_email_log_id"},
ToColumns: []string{"id"},
},
},
}, CommsEmailLogs.Columns.Names(), opts...)
},
ResponseTextLogTextLog: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsTextLog, CommsTextLogSlice](psql.PreloadRel{
Name: "ResponseTextLogTextLog",
Sides: []psql.PreloadSide{
{
From: Communications,
To: CommsTextLogs,
FromColumns: []string{"response_text_log_id"},
ToColumns: []string{"id"},
},
},
}, CommsTextLogs.Columns.Names(), opts...)
},
SetPendingByUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "SetPendingByUser",
Sides: []psql.PreloadSide{
{
From: Communications,
To: Users,
FromColumns: []string{"set_pending_by"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
SetPossibleIssueByUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "SetPossibleIssueByUser",
Sides: []psql.PreloadSide{
{
From: Communications,
To: Users,
FromColumns: []string{"set_possible_issue_by"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
SetPossibleResolvedByUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "SetPossibleResolvedByUser",
Sides: []psql.PreloadSide{
{
From: Communications,
To: Users,
FromColumns: []string{"set_possible_resolved_by"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
SourceEmailLogEmailLog: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsEmailLog, CommsEmailLogSlice](psql.PreloadRel{
Name: "SourceEmailLogEmailLog",
Sides: []psql.PreloadSide{
{
From: Communications,
To: CommsEmailLogs,
FromColumns: []string{"source_email_log_id"},
ToColumns: []string{"id"},
},
},
}, CommsEmailLogs.Columns.Names(), opts...)
},
SourceReportReport: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportReport, PublicreportReportSlice](psql.PreloadRel{
Name: "SourceReportReport",
Sides: []psql.PreloadSide{
{
From: Communications,
To: PublicreportReports,
FromColumns: []string{"source_report_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportReports.Columns.Names(), opts...)
},
SourceTextLogTextLog: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsTextLog, CommsTextLogSlice](psql.PreloadRel{
Name: "SourceTextLogTextLog",
Sides: []psql.PreloadSide{
{
From: Communications,
To: CommsTextLogs,
FromColumns: []string{"source_text_log_id"},
ToColumns: []string{"id"},
},
},
}, CommsTextLogs.Columns.Names(), opts...)
},
}
}
type communicationThenLoader[Q orm.Loadable] struct {
ClosedByUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
InvalidatedByUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
OpenedByUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ResponseEmailLogEmailLog func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ResponseTextLogTextLog func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SetPendingByUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SetPossibleIssueByUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SetPossibleResolvedByUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourceEmailLogEmailLog func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourceReportReport func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourceTextLogTextLog func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommunicationThenLoader[Q orm.Loadable]() communicationThenLoader[Q] {
type ClosedByUserLoadInterface interface {
LoadClosedByUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type InvalidatedByUserLoadInterface interface {
LoadInvalidatedByUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type OpenedByUserLoadInterface interface {
LoadOpenedByUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type OrganizationLoadInterface interface {
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ResponseEmailLogEmailLogLoadInterface interface {
LoadResponseEmailLogEmailLog(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ResponseTextLogTextLogLoadInterface interface {
LoadResponseTextLogTextLog(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SetPendingByUserLoadInterface interface {
LoadSetPendingByUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SetPossibleIssueByUserLoadInterface interface {
LoadSetPossibleIssueByUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SetPossibleResolvedByUserLoadInterface interface {
LoadSetPossibleResolvedByUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SourceEmailLogEmailLogLoadInterface interface {
LoadSourceEmailLogEmailLog(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SourceReportReportLoadInterface interface {
LoadSourceReportReport(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SourceTextLogTextLogLoadInterface interface {
LoadSourceTextLogTextLog(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return communicationThenLoader[Q]{
ClosedByUser: thenLoadBuilder[Q](
"ClosedByUser",
func(ctx context.Context, exec bob.Executor, retrieved ClosedByUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadClosedByUser(ctx, exec, mods...)
},
),
InvalidatedByUser: thenLoadBuilder[Q](
"InvalidatedByUser",
func(ctx context.Context, exec bob.Executor, retrieved InvalidatedByUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadInvalidatedByUser(ctx, exec, mods...)
},
),
OpenedByUser: thenLoadBuilder[Q](
"OpenedByUser",
func(ctx context.Context, exec bob.Executor, retrieved OpenedByUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadOpenedByUser(ctx, exec, mods...)
},
),
Organization: thenLoadBuilder[Q](
"Organization",
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadOrganization(ctx, exec, mods...)
},
),
ResponseEmailLogEmailLog: thenLoadBuilder[Q](
"ResponseEmailLogEmailLog",
func(ctx context.Context, exec bob.Executor, retrieved ResponseEmailLogEmailLogLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadResponseEmailLogEmailLog(ctx, exec, mods...)
},
),
ResponseTextLogTextLog: thenLoadBuilder[Q](
"ResponseTextLogTextLog",
func(ctx context.Context, exec bob.Executor, retrieved ResponseTextLogTextLogLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadResponseTextLogTextLog(ctx, exec, mods...)
},
),
SetPendingByUser: thenLoadBuilder[Q](
"SetPendingByUser",
func(ctx context.Context, exec bob.Executor, retrieved SetPendingByUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSetPendingByUser(ctx, exec, mods...)
},
),
SetPossibleIssueByUser: thenLoadBuilder[Q](
"SetPossibleIssueByUser",
func(ctx context.Context, exec bob.Executor, retrieved SetPossibleIssueByUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSetPossibleIssueByUser(ctx, exec, mods...)
},
),
SetPossibleResolvedByUser: thenLoadBuilder[Q](
"SetPossibleResolvedByUser",
func(ctx context.Context, exec bob.Executor, retrieved SetPossibleResolvedByUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSetPossibleResolvedByUser(ctx, exec, mods...)
},
),
SourceEmailLogEmailLog: thenLoadBuilder[Q](
"SourceEmailLogEmailLog",
func(ctx context.Context, exec bob.Executor, retrieved SourceEmailLogEmailLogLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSourceEmailLogEmailLog(ctx, exec, mods...)
},
),
SourceReportReport: thenLoadBuilder[Q](
"SourceReportReport",
func(ctx context.Context, exec bob.Executor, retrieved SourceReportReportLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSourceReportReport(ctx, exec, mods...)
},
),
SourceTextLogTextLog: thenLoadBuilder[Q](
"SourceTextLogTextLog",
func(ctx context.Context, exec bob.Executor, retrieved SourceTextLogTextLogLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSourceTextLogTextLog(ctx, exec, mods...)
},
),
}
}
// LoadClosedByUser loads the communication's ClosedByUser into the .R struct
func (o *Communication) LoadClosedByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.ClosedByUser = nil
related, err := o.ClosedByUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ClosedByCommunications = CommunicationSlice{o}
o.R.ClosedByUser = related
return nil
}
// LoadClosedByUser loads the communication's ClosedByUser into the .R struct
func (os CommunicationSlice) LoadClosedByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.ClosedByUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !o.ClosedBy.IsValue() {
continue
}
if !(o.ClosedBy.IsValue() && o.ClosedBy.MustGet() == rel.ID) {
continue
}
rel.R.ClosedByCommunications = append(rel.R.ClosedByCommunications, o)
o.R.ClosedByUser = rel
break
}
}
return nil
}
// LoadInvalidatedByUser loads the communication's InvalidatedByUser into the .R struct
func (o *Communication) LoadInvalidatedByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.InvalidatedByUser = nil
related, err := o.InvalidatedByUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.InvalidatedByCommunications = CommunicationSlice{o}
o.R.InvalidatedByUser = related
return nil
}
// LoadInvalidatedByUser loads the communication's InvalidatedByUser into the .R struct
func (os CommunicationSlice) LoadInvalidatedByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.InvalidatedByUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !o.InvalidatedBy.IsValue() {
continue
}
if !(o.InvalidatedBy.IsValue() && o.InvalidatedBy.MustGet() == rel.ID) {
continue
}
rel.R.InvalidatedByCommunications = append(rel.R.InvalidatedByCommunications, o)
o.R.InvalidatedByUser = rel
break
}
}
return nil
}
// LoadOpenedByUser loads the communication's OpenedByUser into the .R struct
func (o *Communication) LoadOpenedByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.OpenedByUser = nil
related, err := o.OpenedByUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.OpenedByCommunications = CommunicationSlice{o}
o.R.OpenedByUser = related
return nil
}
// LoadOpenedByUser loads the communication's OpenedByUser into the .R struct
func (os CommunicationSlice) LoadOpenedByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.OpenedByUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !o.OpenedBy.IsValue() {
continue
}
if !(o.OpenedBy.IsValue() && o.OpenedBy.MustGet() == rel.ID) {
continue
}
rel.R.OpenedByCommunications = append(rel.R.OpenedByCommunications, o)
o.R.OpenedByUser = rel
break
}
}
return nil
}
// LoadOrganization loads the communication's Organization into the .R struct
func (o *Communication) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Organization = nil
related, err := o.Organization(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.Communications = CommunicationSlice{o}
o.R.Organization = related
return nil
}
// LoadOrganization loads the communication's Organization into the .R struct
func (os CommunicationSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
organizations, err := os.Organization(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range organizations {
if !(o.OrganizationID == rel.ID) {
continue
}
rel.R.Communications = append(rel.R.Communications, o)
o.R.Organization = rel
break
}
}
return nil
}
// LoadResponseEmailLogEmailLog loads the communication's ResponseEmailLogEmailLog into the .R struct
func (o *Communication) LoadResponseEmailLogEmailLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.ResponseEmailLogEmailLog = nil
related, err := o.ResponseEmailLogEmailLog(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ResponseEmailLogCommunications = CommunicationSlice{o}
o.R.ResponseEmailLogEmailLog = related
return nil
}
// LoadResponseEmailLogEmailLog loads the communication's ResponseEmailLogEmailLog into the .R struct
func (os CommunicationSlice) LoadResponseEmailLogEmailLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsEmailLogs, err := os.ResponseEmailLogEmailLog(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsEmailLogs {
if !o.ResponseEmailLogID.IsValue() {
continue
}
if !(o.ResponseEmailLogID.IsValue() && o.ResponseEmailLogID.MustGet() == rel.ID) {
continue
}
rel.R.ResponseEmailLogCommunications = append(rel.R.ResponseEmailLogCommunications, o)
o.R.ResponseEmailLogEmailLog = rel
break
}
}
return nil
}
// LoadResponseTextLogTextLog loads the communication's ResponseTextLogTextLog into the .R struct
func (o *Communication) LoadResponseTextLogTextLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.ResponseTextLogTextLog = nil
related, err := o.ResponseTextLogTextLog(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ResponseTextLogCommunications = CommunicationSlice{o}
o.R.ResponseTextLogTextLog = related
return nil
}
// LoadResponseTextLogTextLog loads the communication's ResponseTextLogTextLog into the .R struct
func (os CommunicationSlice) LoadResponseTextLogTextLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsTextLogs, err := os.ResponseTextLogTextLog(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsTextLogs {
if !o.ResponseTextLogID.IsValue() {
continue
}
if !(o.ResponseTextLogID.IsValue() && o.ResponseTextLogID.MustGet() == rel.ID) {
continue
}
rel.R.ResponseTextLogCommunications = append(rel.R.ResponseTextLogCommunications, o)
o.R.ResponseTextLogTextLog = rel
break
}
}
return nil
}
// LoadSetPendingByUser loads the communication's SetPendingByUser into the .R struct
func (o *Communication) LoadSetPendingByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.SetPendingByUser = nil
related, err := o.SetPendingByUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.SetPendingByCommunications = CommunicationSlice{o}
o.R.SetPendingByUser = related
return nil
}
// LoadSetPendingByUser loads the communication's SetPendingByUser into the .R struct
func (os CommunicationSlice) LoadSetPendingByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.SetPendingByUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !o.SetPendingBy.IsValue() {
continue
}
if !(o.SetPendingBy.IsValue() && o.SetPendingBy.MustGet() == rel.ID) {
continue
}
rel.R.SetPendingByCommunications = append(rel.R.SetPendingByCommunications, o)
o.R.SetPendingByUser = rel
break
}
}
return nil
}
// LoadSetPossibleIssueByUser loads the communication's SetPossibleIssueByUser into the .R struct
func (o *Communication) LoadSetPossibleIssueByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.SetPossibleIssueByUser = nil
related, err := o.SetPossibleIssueByUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.SetPossibleIssueByCommunications = CommunicationSlice{o}
o.R.SetPossibleIssueByUser = related
return nil
}
// LoadSetPossibleIssueByUser loads the communication's SetPossibleIssueByUser into the .R struct
func (os CommunicationSlice) LoadSetPossibleIssueByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.SetPossibleIssueByUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !o.SetPossibleIssueBy.IsValue() {
continue
}
if !(o.SetPossibleIssueBy.IsValue() && o.SetPossibleIssueBy.MustGet() == rel.ID) {
continue
}
rel.R.SetPossibleIssueByCommunications = append(rel.R.SetPossibleIssueByCommunications, o)
o.R.SetPossibleIssueByUser = rel
break
}
}
return nil
}
// LoadSetPossibleResolvedByUser loads the communication's SetPossibleResolvedByUser into the .R struct
func (o *Communication) LoadSetPossibleResolvedByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.SetPossibleResolvedByUser = nil
related, err := o.SetPossibleResolvedByUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.SetPossibleResolvedByCommunications = CommunicationSlice{o}
o.R.SetPossibleResolvedByUser = related
return nil
}
// LoadSetPossibleResolvedByUser loads the communication's SetPossibleResolvedByUser into the .R struct
func (os CommunicationSlice) LoadSetPossibleResolvedByUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.SetPossibleResolvedByUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !o.SetPossibleResolvedBy.IsValue() {
continue
}
if !(o.SetPossibleResolvedBy.IsValue() && o.SetPossibleResolvedBy.MustGet() == rel.ID) {
continue
}
rel.R.SetPossibleResolvedByCommunications = append(rel.R.SetPossibleResolvedByCommunications, o)
o.R.SetPossibleResolvedByUser = rel
break
}
}
return nil
}
// LoadSourceEmailLogEmailLog loads the communication's SourceEmailLogEmailLog into the .R struct
func (o *Communication) LoadSourceEmailLogEmailLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.SourceEmailLogEmailLog = nil
related, err := o.SourceEmailLogEmailLog(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.SourceEmailLogCommunications = CommunicationSlice{o}
o.R.SourceEmailLogEmailLog = related
return nil
}
// LoadSourceEmailLogEmailLog loads the communication's SourceEmailLogEmailLog into the .R struct
func (os CommunicationSlice) LoadSourceEmailLogEmailLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsEmailLogs, err := os.SourceEmailLogEmailLog(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsEmailLogs {
if !o.SourceEmailLogID.IsValue() {
continue
}
if !(o.SourceEmailLogID.IsValue() && o.SourceEmailLogID.MustGet() == rel.ID) {
continue
}
rel.R.SourceEmailLogCommunications = append(rel.R.SourceEmailLogCommunications, o)
o.R.SourceEmailLogEmailLog = rel
break
}
}
return nil
}
// LoadSourceReportReport loads the communication's SourceReportReport into the .R struct
func (o *Communication) LoadSourceReportReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.SourceReportReport = nil
related, err := o.SourceReportReport(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.SourceReportCommunications = CommunicationSlice{o}
o.R.SourceReportReport = related
return nil
}
// LoadSourceReportReport loads the communication's SourceReportReport into the .R struct
func (os CommunicationSlice) LoadSourceReportReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportReports, err := os.SourceReportReport(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportReports {
if !o.SourceReportID.IsValue() {
continue
}
if !(o.SourceReportID.IsValue() && o.SourceReportID.MustGet() == rel.ID) {
continue
}
rel.R.SourceReportCommunications = append(rel.R.SourceReportCommunications, o)
o.R.SourceReportReport = rel
break
}
}
return nil
}
// LoadSourceTextLogTextLog loads the communication's SourceTextLogTextLog into the .R struct
func (o *Communication) LoadSourceTextLogTextLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.SourceTextLogTextLog = nil
related, err := o.SourceTextLogTextLog(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.SourceTextLogCommunications = CommunicationSlice{o}
o.R.SourceTextLogTextLog = related
return nil
}
// LoadSourceTextLogTextLog loads the communication's SourceTextLogTextLog into the .R struct
func (os CommunicationSlice) LoadSourceTextLogTextLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsTextLogs, err := os.SourceTextLogTextLog(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsTextLogs {
if !o.SourceTextLogID.IsValue() {
continue
}
if !(o.SourceTextLogID.IsValue() && o.SourceTextLogID.MustGet() == rel.ID) {
continue
}
rel.R.SourceTextLogCommunications = append(rel.R.SourceTextLogCommunications, o)
o.R.SourceTextLogTextLog = rel
break
}
}
return nil
}