From a82b2b8cb833f77a91a37f0418f0b6b918c05e0e Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 1 May 2026 15:13:05 +0000 Subject: [PATCH] Add new communication table It allows us to track when communication tasks are complete, and information about how they were completed, separate from the entries that created the tasks in the first place (reports, emails, texts) --- db/dberrors/communication.bob.go | 17 + db/dbinfo/communication.bob.go | 327 ++++ db/migrations/00147_communication.sql | 21 + db/models/bob_loaders.bob.go | 4 + db/models/bob_where.bob.go | 3 + db/models/comms.email_log.bob.go | 374 ++++- db/models/comms.text_log.bob.go | 378 ++++- db/models/communication.bob.go | 2215 +++++++++++++++++++++++++ db/models/publicreport.report.bob.go | 237 ++- db/models/user_.bob.go | 724 ++++++++ 10 files changed, 4258 insertions(+), 42 deletions(-) create mode 100644 db/dberrors/communication.bob.go create mode 100644 db/dbinfo/communication.bob.go create mode 100644 db/migrations/00147_communication.sql create mode 100644 db/models/communication.bob.go diff --git a/db/dberrors/communication.bob.go b/db/dberrors/communication.bob.go new file mode 100644 index 00000000..f390b99a --- /dev/null +++ b/db/dberrors/communication.bob.go @@ -0,0 +1,17 @@ +// 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 dberrors + +var CommunicationErrors = &communicationErrors{ + ErrUniqueCommunicationPkey: &UniqueConstraintError{ + schema: "", + table: "communication", + columns: []string{"id"}, + s: "communication_pkey", + }, +} + +type communicationErrors struct { + ErrUniqueCommunicationPkey *UniqueConstraintError +} diff --git a/db/dbinfo/communication.bob.go b/db/dbinfo/communication.bob.go new file mode 100644 index 00000000..a0849ad7 --- /dev/null +++ b/db/dbinfo/communication.bob.go @@ -0,0 +1,327 @@ +// 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 dbinfo + +import "github.com/aarondl/opt/null" + +var Communications = Table[ + communicationColumns, + communicationIndexes, + communicationForeignKeys, + communicationUniques, + communicationChecks, +]{ + Schema: "", + Name: "communication", + Columns: communicationColumns{ + Closed: column{ + Name: "closed", + DBType: "timestamp without time zone", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + ClosedBy: column{ + Name: "closed_by", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + Created: column{ + Name: "created", + DBType: "timestamp without time zone", + Default: "", + Comment: "", + Nullable: false, + Generated: false, + AutoIncr: false, + }, + ID: column{ + Name: "id", + DBType: "integer", + Default: "nextval('communication_id_seq'::regclass)", + Comment: "", + Nullable: false, + Generated: false, + AutoIncr: false, + }, + Invalidated: column{ + Name: "invalidated", + DBType: "timestamp without time zone", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + InvalidatedBy: column{ + Name: "invalidated_by", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + Opened: column{ + Name: "opened", + DBType: "timestamp without time zone", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + OpenedBy: column{ + Name: "opened_by", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + ResponseEmailLogID: column{ + Name: "response_email_log_id", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + ResponseTextLogID: column{ + Name: "response_text_log_id", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + SetPending: column{ + Name: "set_pending", + DBType: "timestamp without time zone", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + SetPendingBy: column{ + Name: "set_pending_by", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + SourceEmailLogID: column{ + Name: "source_email_log_id", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + SourceReportID: column{ + Name: "source_report_id", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + SourceTextLogID: column{ + Name: "source_text_log_id", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + }, + Indexes: communicationIndexes{ + CommunicationPkey: index{ + Type: "btree", + Name: "communication_pkey", + Columns: []indexColumn{ + { + Name: "id", + Desc: null.FromCond(false, true), + IsExpression: false, + }, + }, + Unique: true, + Comment: "", + NullsFirst: []bool{false}, + NullsDistinct: false, + Where: "", + Include: []string{}, + }, + }, + PrimaryKey: &constraint{ + Name: "communication_pkey", + Columns: []string{"id"}, + Comment: "", + }, + ForeignKeys: communicationForeignKeys{ + CommunicationCommunicationClosedByFkey: foreignKey{ + constraint: constraint{ + Name: "communication.communication_closed_by_fkey", + Columns: []string{"closed_by"}, + Comment: "", + }, + ForeignTable: "user_", + ForeignColumns: []string{"id"}, + }, + CommunicationCommunicationInvalidatedByFkey: foreignKey{ + constraint: constraint{ + Name: "communication.communication_invalidated_by_fkey", + Columns: []string{"invalidated_by"}, + Comment: "", + }, + ForeignTable: "user_", + ForeignColumns: []string{"id"}, + }, + CommunicationCommunicationOpenedByFkey: foreignKey{ + constraint: constraint{ + Name: "communication.communication_opened_by_fkey", + Columns: []string{"opened_by"}, + Comment: "", + }, + ForeignTable: "user_", + ForeignColumns: []string{"id"}, + }, + CommunicationCommunicationResponseEmailLogIDFkey: foreignKey{ + constraint: constraint{ + Name: "communication.communication_response_email_log_id_fkey", + Columns: []string{"response_email_log_id"}, + Comment: "", + }, + ForeignTable: "comms.email_log", + ForeignColumns: []string{"id"}, + }, + CommunicationCommunicationResponseTextLogIDFkey: foreignKey{ + constraint: constraint{ + Name: "communication.communication_response_text_log_id_fkey", + Columns: []string{"response_text_log_id"}, + Comment: "", + }, + ForeignTable: "comms.text_log", + ForeignColumns: []string{"id"}, + }, + CommunicationCommunicationSetPendingByFkey: foreignKey{ + constraint: constraint{ + Name: "communication.communication_set_pending_by_fkey", + Columns: []string{"set_pending_by"}, + Comment: "", + }, + ForeignTable: "user_", + ForeignColumns: []string{"id"}, + }, + CommunicationCommunicationSourceEmailLogIDFkey: foreignKey{ + constraint: constraint{ + Name: "communication.communication_source_email_log_id_fkey", + Columns: []string{"source_email_log_id"}, + Comment: "", + }, + ForeignTable: "comms.email_log", + ForeignColumns: []string{"id"}, + }, + CommunicationCommunicationSourceReportIDFkey: foreignKey{ + constraint: constraint{ + Name: "communication.communication_source_report_id_fkey", + Columns: []string{"source_report_id"}, + Comment: "", + }, + ForeignTable: "publicreport.report", + ForeignColumns: []string{"id"}, + }, + CommunicationCommunicationSourceTextLogIDFkey: foreignKey{ + constraint: constraint{ + Name: "communication.communication_source_text_log_id_fkey", + Columns: []string{"source_text_log_id"}, + Comment: "", + }, + ForeignTable: "comms.text_log", + ForeignColumns: []string{"id"}, + }, + }, + + Comment: "", +} + +type communicationColumns struct { + Closed column + ClosedBy column + Created column + ID column + Invalidated column + InvalidatedBy column + Opened column + OpenedBy column + ResponseEmailLogID column + ResponseTextLogID column + SetPending column + SetPendingBy column + SourceEmailLogID column + SourceReportID column + SourceTextLogID column +} + +func (c communicationColumns) AsSlice() []column { + return []column{ + c.Closed, c.ClosedBy, c.Created, c.ID, c.Invalidated, c.InvalidatedBy, c.Opened, c.OpenedBy, c.ResponseEmailLogID, c.ResponseTextLogID, c.SetPending, c.SetPendingBy, c.SourceEmailLogID, c.SourceReportID, c.SourceTextLogID, + } +} + +type communicationIndexes struct { + CommunicationPkey index +} + +func (i communicationIndexes) AsSlice() []index { + return []index{ + i.CommunicationPkey, + } +} + +type communicationForeignKeys struct { + CommunicationCommunicationClosedByFkey foreignKey + CommunicationCommunicationInvalidatedByFkey foreignKey + CommunicationCommunicationOpenedByFkey foreignKey + CommunicationCommunicationResponseEmailLogIDFkey foreignKey + CommunicationCommunicationResponseTextLogIDFkey foreignKey + CommunicationCommunicationSetPendingByFkey foreignKey + CommunicationCommunicationSourceEmailLogIDFkey foreignKey + CommunicationCommunicationSourceReportIDFkey foreignKey + CommunicationCommunicationSourceTextLogIDFkey foreignKey +} + +func (f communicationForeignKeys) AsSlice() []foreignKey { + return []foreignKey{ + f.CommunicationCommunicationClosedByFkey, f.CommunicationCommunicationInvalidatedByFkey, f.CommunicationCommunicationOpenedByFkey, f.CommunicationCommunicationResponseEmailLogIDFkey, f.CommunicationCommunicationResponseTextLogIDFkey, f.CommunicationCommunicationSetPendingByFkey, f.CommunicationCommunicationSourceEmailLogIDFkey, f.CommunicationCommunicationSourceReportIDFkey, f.CommunicationCommunicationSourceTextLogIDFkey, + } +} + +type communicationUniques struct{} + +func (u communicationUniques) AsSlice() []constraint { + return []constraint{} +} + +type communicationChecks struct{} + +func (c communicationChecks) AsSlice() []check { + return []check{} +} diff --git a/db/migrations/00147_communication.sql b/db/migrations/00147_communication.sql new file mode 100644 index 00000000..57577061 --- /dev/null +++ b/db/migrations/00147_communication.sql @@ -0,0 +1,21 @@ +-- +goose Up +CREATE TABLE communication ( + closed TIMESTAMP WITHOUT TIME ZONE, + closed_by INTEGER REFERENCES user_(id), + created TIMESTAMP WITHOUT TIME ZONE NOT NULL, + id SERIAL, + invalidated TIMESTAMP WITHOUT TIME ZONE, + invalidated_by INTEGER REFERENCES user_(id), + opened TIMESTAMP WITHOUT TIME ZONE, + opened_by INTEGER REFERENCES user_(id), + response_email_log_id INTEGER REFERENCES comms.email_log(id), + response_text_log_id INTEGER REFERENCES comms.text_log(id), + set_pending TIMESTAMP WITHOUT TIME ZONE, + set_pending_by INTEGER REFERENCES user_(id), + source_email_log_id INTEGER REFERENCES comms.email_log(id), + source_report_id INTEGER REFERENCES publicreport.report(id), + source_text_log_id INTEGER REFERENCES comms.text_log(id), + PRIMARY KEY(id) +); +-- +goose Down +DROP TABLE communication; diff --git a/db/models/bob_loaders.bob.go b/db/models/bob_loaders.bob.go index d8416bd6..132a439f 100644 --- a/db/models/bob_loaders.bob.go +++ b/db/models/bob_loaders.bob.go @@ -35,6 +35,7 @@ type preloaders struct { CommsPhone commsPhonePreloader CommsTextJob commsTextJobPreloader CommsTextLog commsTextLogPreloader + Communication communicationPreloader ComplianceReportRequest complianceReportRequestPreloader ComplianceReportRequestMailer complianceReportRequestMailerPreloader DistrictSubscriptionEmail districtSubscriptionEmailPreloader @@ -138,6 +139,7 @@ func getPreloaders() preloaders { CommsPhone: buildCommsPhonePreloader(), CommsTextJob: buildCommsTextJobPreloader(), CommsTextLog: buildCommsTextLogPreloader(), + Communication: buildCommunicationPreloader(), ComplianceReportRequest: buildComplianceReportRequestPreloader(), ComplianceReportRequestMailer: buildComplianceReportRequestMailerPreloader(), DistrictSubscriptionEmail: buildDistrictSubscriptionEmailPreloader(), @@ -247,6 +249,7 @@ type thenLoaders[Q orm.Loadable] struct { CommsPhone commsPhoneThenLoader[Q] CommsTextJob commsTextJobThenLoader[Q] CommsTextLog commsTextLogThenLoader[Q] + Communication communicationThenLoader[Q] ComplianceReportRequest complianceReportRequestThenLoader[Q] ComplianceReportRequestMailer complianceReportRequestMailerThenLoader[Q] DistrictSubscriptionEmail districtSubscriptionEmailThenLoader[Q] @@ -350,6 +353,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] { CommsPhone: buildCommsPhoneThenLoader[Q](), CommsTextJob: buildCommsTextJobThenLoader[Q](), CommsTextLog: buildCommsTextLogThenLoader[Q](), + Communication: buildCommunicationThenLoader[Q](), ComplianceReportRequest: buildComplianceReportRequestThenLoader[Q](), ComplianceReportRequestMailer: buildComplianceReportRequestMailerThenLoader[Q](), DistrictSubscriptionEmail: buildDistrictSubscriptionEmailThenLoader[Q](), diff --git a/db/models/bob_where.bob.go b/db/models/bob_where.bob.go index eb8f2c71..43062d3b 100644 --- a/db/models/bob_where.bob.go +++ b/db/models/bob_where.bob.go @@ -35,6 +35,7 @@ func Where[Q psql.Filterable]() struct { CommsPhones commsPhoneWhere[Q] CommsTextJobs commsTextJobWhere[Q] CommsTextLogs commsTextLogWhere[Q] + Communications communicationWhere[Q] ComplianceReportRequests complianceReportRequestWhere[Q] ComplianceReportRequestMailers complianceReportRequestMailerWhere[Q] DistrictSubscriptionEmails districtSubscriptionEmailWhere[Q] @@ -146,6 +147,7 @@ func Where[Q psql.Filterable]() struct { CommsPhones commsPhoneWhere[Q] CommsTextJobs commsTextJobWhere[Q] CommsTextLogs commsTextLogWhere[Q] + Communications communicationWhere[Q] ComplianceReportRequests complianceReportRequestWhere[Q] ComplianceReportRequestMailers complianceReportRequestMailerWhere[Q] DistrictSubscriptionEmails districtSubscriptionEmailWhere[Q] @@ -256,6 +258,7 @@ func Where[Q psql.Filterable]() struct { CommsPhones: buildCommsPhoneWhere[Q](CommsPhones.Columns), CommsTextJobs: buildCommsTextJobWhere[Q](CommsTextJobs.Columns), CommsTextLogs: buildCommsTextLogWhere[Q](CommsTextLogs.Columns), + Communications: buildCommunicationWhere[Q](Communications.Columns), ComplianceReportRequests: buildComplianceReportRequestWhere[Q](ComplianceReportRequests.Columns), ComplianceReportRequestMailers: buildComplianceReportRequestMailerWhere[Q](ComplianceReportRequestMailers.Columns), DistrictSubscriptionEmails: buildDistrictSubscriptionEmailWhere[Q](DistrictSubscriptionEmails.Columns), diff --git a/db/models/comms.email_log.bob.go b/db/models/comms.email_log.bob.go index 92314eec..60ef0c97 100644 --- a/db/models/comms.email_log.bob.go +++ b/db/models/comms.email_log.bob.go @@ -53,9 +53,11 @@ type CommsEmailLogsQuery = *psql.ViewQuery[*CommsEmailLog, CommsEmailLogSlice] // commsEmailLogR is where relationships are stored. type commsEmailLogR struct { - DestinationEmailContact *CommsEmailContact // comms.email_log.email_log_destination_fkey - TemplateEmailTemplate *CommsEmailTemplate // comms.email_log.email_log_template_id_fkey - ReportLogs PublicreportReportLogSlice // publicreport.report_log.report_log_email_log_id_fkey + DestinationEmailContact *CommsEmailContact // comms.email_log.email_log_destination_fkey + TemplateEmailTemplate *CommsEmailTemplate // comms.email_log.email_log_template_id_fkey + ResponseEmailLogCommunications CommunicationSlice // communication.communication_response_email_log_id_fkey + SourceEmailLogCommunications CommunicationSlice // communication.communication_source_email_log_id_fkey + ReportLogs PublicreportReportLogSlice // publicreport.report_log.report_log_email_log_id_fkey } func buildCommsEmailLogColumns(alias string) commsEmailLogColumns { @@ -628,6 +630,54 @@ func (os CommsEmailLogSlice) TemplateEmailTemplate(mods ...bob.Mod[*dialect.Sele )...) } +// ResponseEmailLogCommunications starts a query for related objects on communication +func (o *CommsEmailLog) ResponseEmailLogCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + return Communications.Query(append(mods, + sm.Where(Communications.Columns.ResponseEmailLogID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os CommsEmailLogSlice) ResponseEmailLogCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return Communications.Query(append(mods, + sm.Where(psql.Group(Communications.Columns.ResponseEmailLogID).OP("IN", PKArgExpr)), + )...) +} + +// SourceEmailLogCommunications starts a query for related objects on communication +func (o *CommsEmailLog) SourceEmailLogCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + return Communications.Query(append(mods, + sm.Where(Communications.Columns.SourceEmailLogID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os CommsEmailLogSlice) SourceEmailLogCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return Communications.Query(append(mods, + sm.Where(psql.Group(Communications.Columns.SourceEmailLogID).OP("IN", PKArgExpr)), + )...) +} + // ReportLogs starts a query for related objects on publicreport.report_log func (o *CommsEmailLog) ReportLogs(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportLogsQuery { return PublicreportReportLogs.Query(append(mods, @@ -748,6 +798,142 @@ func (commsEmailLog0 *CommsEmailLog) AttachTemplateEmailTemplate(ctx context.Con return nil } +func insertCommsEmailLogResponseEmailLogCommunications0(ctx context.Context, exec bob.Executor, communications1 []*CommunicationSetter, commsEmailLog0 *CommsEmailLog) (CommunicationSlice, error) { + for i := range communications1 { + communications1[i].ResponseEmailLogID = omitnull.From(commsEmailLog0.ID) + } + + ret, err := Communications.Insert(bob.ToMods(communications1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertCommsEmailLogResponseEmailLogCommunications0: %w", err) + } + + return ret, nil +} + +func attachCommsEmailLogResponseEmailLogCommunications0(ctx context.Context, exec bob.Executor, count int, communications1 CommunicationSlice, commsEmailLog0 *CommsEmailLog) (CommunicationSlice, error) { + setter := &CommunicationSetter{ + ResponseEmailLogID: omitnull.From(commsEmailLog0.ID), + } + + err := communications1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachCommsEmailLogResponseEmailLogCommunications0: %w", err) + } + + return communications1, nil +} + +func (commsEmailLog0 *CommsEmailLog) InsertResponseEmailLogCommunications(ctx context.Context, exec bob.Executor, related ...*CommunicationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + communications1, err := insertCommsEmailLogResponseEmailLogCommunications0(ctx, exec, related, commsEmailLog0) + if err != nil { + return err + } + + commsEmailLog0.R.ResponseEmailLogCommunications = append(commsEmailLog0.R.ResponseEmailLogCommunications, communications1...) + + for _, rel := range communications1 { + rel.R.ResponseEmailLogEmailLog = commsEmailLog0 + } + return nil +} + +func (commsEmailLog0 *CommsEmailLog) AttachResponseEmailLogCommunications(ctx context.Context, exec bob.Executor, related ...*Communication) error { + if len(related) == 0 { + return nil + } + + var err error + communications1 := CommunicationSlice(related) + + _, err = attachCommsEmailLogResponseEmailLogCommunications0(ctx, exec, len(related), communications1, commsEmailLog0) + if err != nil { + return err + } + + commsEmailLog0.R.ResponseEmailLogCommunications = append(commsEmailLog0.R.ResponseEmailLogCommunications, communications1...) + + for _, rel := range related { + rel.R.ResponseEmailLogEmailLog = commsEmailLog0 + } + + return nil +} + +func insertCommsEmailLogSourceEmailLogCommunications0(ctx context.Context, exec bob.Executor, communications1 []*CommunicationSetter, commsEmailLog0 *CommsEmailLog) (CommunicationSlice, error) { + for i := range communications1 { + communications1[i].SourceEmailLogID = omitnull.From(commsEmailLog0.ID) + } + + ret, err := Communications.Insert(bob.ToMods(communications1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertCommsEmailLogSourceEmailLogCommunications0: %w", err) + } + + return ret, nil +} + +func attachCommsEmailLogSourceEmailLogCommunications0(ctx context.Context, exec bob.Executor, count int, communications1 CommunicationSlice, commsEmailLog0 *CommsEmailLog) (CommunicationSlice, error) { + setter := &CommunicationSetter{ + SourceEmailLogID: omitnull.From(commsEmailLog0.ID), + } + + err := communications1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachCommsEmailLogSourceEmailLogCommunications0: %w", err) + } + + return communications1, nil +} + +func (commsEmailLog0 *CommsEmailLog) InsertSourceEmailLogCommunications(ctx context.Context, exec bob.Executor, related ...*CommunicationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + communications1, err := insertCommsEmailLogSourceEmailLogCommunications0(ctx, exec, related, commsEmailLog0) + if err != nil { + return err + } + + commsEmailLog0.R.SourceEmailLogCommunications = append(commsEmailLog0.R.SourceEmailLogCommunications, communications1...) + + for _, rel := range communications1 { + rel.R.SourceEmailLogEmailLog = commsEmailLog0 + } + return nil +} + +func (commsEmailLog0 *CommsEmailLog) AttachSourceEmailLogCommunications(ctx context.Context, exec bob.Executor, related ...*Communication) error { + if len(related) == 0 { + return nil + } + + var err error + communications1 := CommunicationSlice(related) + + _, err = attachCommsEmailLogSourceEmailLogCommunications0(ctx, exec, len(related), communications1, commsEmailLog0) + if err != nil { + return err + } + + commsEmailLog0.R.SourceEmailLogCommunications = append(commsEmailLog0.R.SourceEmailLogCommunications, communications1...) + + for _, rel := range related { + rel.R.SourceEmailLogEmailLog = commsEmailLog0 + } + + return nil +} + func insertCommsEmailLogReportLogs0(ctx context.Context, exec bob.Executor, publicreportReportLogs1 []*PublicreportReportLogSetter, commsEmailLog0 *CommsEmailLog) (PublicreportReportLogSlice, error) { for i := range publicreportReportLogs1 { publicreportReportLogs1[i].EmailLogID = omitnull.From(commsEmailLog0.ID) @@ -880,6 +1066,34 @@ func (o *CommsEmailLog) Preload(name string, retrieved any) error { rel.R.TemplateEmailLogs = CommsEmailLogSlice{o} } return nil + case "ResponseEmailLogCommunications": + rels, ok := retrieved.(CommunicationSlice) + if !ok { + return fmt.Errorf("commsEmailLog cannot load %T as %q", retrieved, name) + } + + o.R.ResponseEmailLogCommunications = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ResponseEmailLogEmailLog = o + } + } + return nil + case "SourceEmailLogCommunications": + rels, ok := retrieved.(CommunicationSlice) + if !ok { + return fmt.Errorf("commsEmailLog cannot load %T as %q", retrieved, name) + } + + o.R.SourceEmailLogCommunications = rels + + for _, rel := range rels { + if rel != nil { + rel.R.SourceEmailLogEmailLog = o + } + } + return nil case "ReportLogs": rels, ok := retrieved.(PublicreportReportLogSlice) if !ok { @@ -936,9 +1150,11 @@ func buildCommsEmailLogPreloader() commsEmailLogPreloader { } type commsEmailLogThenLoader[Q orm.Loadable] struct { - DestinationEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - TemplateEmailTemplate func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReportLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + DestinationEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + TemplateEmailTemplate func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ResponseEmailLogCommunications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SourceEmailLogCommunications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReportLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildCommsEmailLogThenLoader[Q orm.Loadable]() commsEmailLogThenLoader[Q] { @@ -948,6 +1164,12 @@ func buildCommsEmailLogThenLoader[Q orm.Loadable]() commsEmailLogThenLoader[Q] { type TemplateEmailTemplateLoadInterface interface { LoadTemplateEmailTemplate(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type ResponseEmailLogCommunicationsLoadInterface interface { + LoadResponseEmailLogCommunications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SourceEmailLogCommunicationsLoadInterface interface { + LoadSourceEmailLogCommunications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type ReportLogsLoadInterface interface { LoadReportLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -965,6 +1187,18 @@ func buildCommsEmailLogThenLoader[Q orm.Loadable]() commsEmailLogThenLoader[Q] { return retrieved.LoadTemplateEmailTemplate(ctx, exec, mods...) }, ), + ResponseEmailLogCommunications: thenLoadBuilder[Q]( + "ResponseEmailLogCommunications", + func(ctx context.Context, exec bob.Executor, retrieved ResponseEmailLogCommunicationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadResponseEmailLogCommunications(ctx, exec, mods...) + }, + ), + SourceEmailLogCommunications: thenLoadBuilder[Q]( + "SourceEmailLogCommunications", + func(ctx context.Context, exec bob.Executor, retrieved SourceEmailLogCommunicationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSourceEmailLogCommunications(ctx, exec, mods...) + }, + ), ReportLogs: thenLoadBuilder[Q]( "ReportLogs", func(ctx context.Context, exec bob.Executor, retrieved ReportLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -1078,6 +1312,134 @@ func (os CommsEmailLogSlice) LoadTemplateEmailTemplate(ctx context.Context, exec return nil } +// LoadResponseEmailLogCommunications loads the commsEmailLog's ResponseEmailLogCommunications into the .R struct +func (o *CommsEmailLog) LoadResponseEmailLogCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ResponseEmailLogCommunications = nil + + related, err := o.ResponseEmailLogCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ResponseEmailLogEmailLog = o + } + + o.R.ResponseEmailLogCommunications = related + return nil +} + +// LoadResponseEmailLogCommunications loads the commsEmailLog's ResponseEmailLogCommunications into the .R struct +func (os CommsEmailLogSlice) LoadResponseEmailLogCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + communications, err := os.ResponseEmailLogCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ResponseEmailLogCommunications = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range communications { + + if !rel.ResponseEmailLogID.IsValue() { + continue + } + if !(rel.ResponseEmailLogID.IsValue() && o.ID == rel.ResponseEmailLogID.MustGet()) { + continue + } + + rel.R.ResponseEmailLogEmailLog = o + + o.R.ResponseEmailLogCommunications = append(o.R.ResponseEmailLogCommunications, rel) + } + } + + return nil +} + +// LoadSourceEmailLogCommunications loads the commsEmailLog's SourceEmailLogCommunications into the .R struct +func (o *CommsEmailLog) LoadSourceEmailLogCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SourceEmailLogCommunications = nil + + related, err := o.SourceEmailLogCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.SourceEmailLogEmailLog = o + } + + o.R.SourceEmailLogCommunications = related + return nil +} + +// LoadSourceEmailLogCommunications loads the commsEmailLog's SourceEmailLogCommunications into the .R struct +func (os CommsEmailLogSlice) LoadSourceEmailLogCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + communications, err := os.SourceEmailLogCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.SourceEmailLogCommunications = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range communications { + + if !rel.SourceEmailLogID.IsValue() { + continue + } + if !(rel.SourceEmailLogID.IsValue() && o.ID == rel.SourceEmailLogID.MustGet()) { + continue + } + + rel.R.SourceEmailLogEmailLog = o + + o.R.SourceEmailLogCommunications = append(o.R.SourceEmailLogCommunications, rel) + } + } + + return nil +} + // LoadReportLogs loads the commsEmailLog's ReportLogs into the .R struct func (o *CommsEmailLog) LoadReportLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { diff --git a/db/models/comms.text_log.bob.go b/db/models/comms.text_log.bob.go index 10d2af05..c135f0c9 100644 --- a/db/models/comms.text_log.bob.go +++ b/db/models/comms.text_log.bob.go @@ -52,10 +52,12 @@ type CommsTextLogsQuery = *psql.ViewQuery[*CommsTextLog, CommsTextLogSlice] // commsTextLogR is where relationships are stored. type commsTextLogR struct { - DestinationPhone *CommsPhone // comms.text_log.text_log_destination_fkey - SourcePhone *CommsPhone // comms.text_log.text_log_source_fkey - ReportLogs PublicreportReportLogSlice // publicreport.report_log.report_log_text_log_id_fkey - ReportTexts ReportTextSlice // report_text.report_text_text_log_id_fkey + DestinationPhone *CommsPhone // comms.text_log.text_log_destination_fkey + SourcePhone *CommsPhone // comms.text_log.text_log_source_fkey + ResponseTextLogCommunications CommunicationSlice // communication.communication_response_text_log_id_fkey + SourceTextLogCommunications CommunicationSlice // communication.communication_source_text_log_id_fkey + ReportLogs PublicreportReportLogSlice // publicreport.report_log.report_log_text_log_id_fkey + ReportTexts ReportTextSlice // report_text.report_text_text_log_id_fkey } func buildCommsTextLogColumns(alias string) commsTextLogColumns { @@ -606,6 +608,54 @@ func (os CommsTextLogSlice) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) C )...) } +// ResponseTextLogCommunications starts a query for related objects on communication +func (o *CommsTextLog) ResponseTextLogCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + return Communications.Query(append(mods, + sm.Where(Communications.Columns.ResponseTextLogID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os CommsTextLogSlice) ResponseTextLogCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return Communications.Query(append(mods, + sm.Where(psql.Group(Communications.Columns.ResponseTextLogID).OP("IN", PKArgExpr)), + )...) +} + +// SourceTextLogCommunications starts a query for related objects on communication +func (o *CommsTextLog) SourceTextLogCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + return Communications.Query(append(mods, + sm.Where(Communications.Columns.SourceTextLogID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os CommsTextLogSlice) SourceTextLogCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return Communications.Query(append(mods, + sm.Where(psql.Group(Communications.Columns.SourceTextLogID).OP("IN", PKArgExpr)), + )...) +} + // ReportLogs starts a query for related objects on publicreport.report_log func (o *CommsTextLog) ReportLogs(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportLogsQuery { return PublicreportReportLogs.Query(append(mods, @@ -750,6 +800,142 @@ func (commsTextLog0 *CommsTextLog) AttachSourcePhone(ctx context.Context, exec b return nil } +func insertCommsTextLogResponseTextLogCommunications0(ctx context.Context, exec bob.Executor, communications1 []*CommunicationSetter, commsTextLog0 *CommsTextLog) (CommunicationSlice, error) { + for i := range communications1 { + communications1[i].ResponseTextLogID = omitnull.From(commsTextLog0.ID) + } + + ret, err := Communications.Insert(bob.ToMods(communications1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertCommsTextLogResponseTextLogCommunications0: %w", err) + } + + return ret, nil +} + +func attachCommsTextLogResponseTextLogCommunications0(ctx context.Context, exec bob.Executor, count int, communications1 CommunicationSlice, commsTextLog0 *CommsTextLog) (CommunicationSlice, error) { + setter := &CommunicationSetter{ + ResponseTextLogID: omitnull.From(commsTextLog0.ID), + } + + err := communications1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachCommsTextLogResponseTextLogCommunications0: %w", err) + } + + return communications1, nil +} + +func (commsTextLog0 *CommsTextLog) InsertResponseTextLogCommunications(ctx context.Context, exec bob.Executor, related ...*CommunicationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + communications1, err := insertCommsTextLogResponseTextLogCommunications0(ctx, exec, related, commsTextLog0) + if err != nil { + return err + } + + commsTextLog0.R.ResponseTextLogCommunications = append(commsTextLog0.R.ResponseTextLogCommunications, communications1...) + + for _, rel := range communications1 { + rel.R.ResponseTextLogTextLog = commsTextLog0 + } + return nil +} + +func (commsTextLog0 *CommsTextLog) AttachResponseTextLogCommunications(ctx context.Context, exec bob.Executor, related ...*Communication) error { + if len(related) == 0 { + return nil + } + + var err error + communications1 := CommunicationSlice(related) + + _, err = attachCommsTextLogResponseTextLogCommunications0(ctx, exec, len(related), communications1, commsTextLog0) + if err != nil { + return err + } + + commsTextLog0.R.ResponseTextLogCommunications = append(commsTextLog0.R.ResponseTextLogCommunications, communications1...) + + for _, rel := range related { + rel.R.ResponseTextLogTextLog = commsTextLog0 + } + + return nil +} + +func insertCommsTextLogSourceTextLogCommunications0(ctx context.Context, exec bob.Executor, communications1 []*CommunicationSetter, commsTextLog0 *CommsTextLog) (CommunicationSlice, error) { + for i := range communications1 { + communications1[i].SourceTextLogID = omitnull.From(commsTextLog0.ID) + } + + ret, err := Communications.Insert(bob.ToMods(communications1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertCommsTextLogSourceTextLogCommunications0: %w", err) + } + + return ret, nil +} + +func attachCommsTextLogSourceTextLogCommunications0(ctx context.Context, exec bob.Executor, count int, communications1 CommunicationSlice, commsTextLog0 *CommsTextLog) (CommunicationSlice, error) { + setter := &CommunicationSetter{ + SourceTextLogID: omitnull.From(commsTextLog0.ID), + } + + err := communications1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachCommsTextLogSourceTextLogCommunications0: %w", err) + } + + return communications1, nil +} + +func (commsTextLog0 *CommsTextLog) InsertSourceTextLogCommunications(ctx context.Context, exec bob.Executor, related ...*CommunicationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + communications1, err := insertCommsTextLogSourceTextLogCommunications0(ctx, exec, related, commsTextLog0) + if err != nil { + return err + } + + commsTextLog0.R.SourceTextLogCommunications = append(commsTextLog0.R.SourceTextLogCommunications, communications1...) + + for _, rel := range communications1 { + rel.R.SourceTextLogTextLog = commsTextLog0 + } + return nil +} + +func (commsTextLog0 *CommsTextLog) AttachSourceTextLogCommunications(ctx context.Context, exec bob.Executor, related ...*Communication) error { + if len(related) == 0 { + return nil + } + + var err error + communications1 := CommunicationSlice(related) + + _, err = attachCommsTextLogSourceTextLogCommunications0(ctx, exec, len(related), communications1, commsTextLog0) + if err != nil { + return err + } + + commsTextLog0.R.SourceTextLogCommunications = append(commsTextLog0.R.SourceTextLogCommunications, communications1...) + + for _, rel := range related { + rel.R.SourceTextLogTextLog = commsTextLog0 + } + + return nil +} + func insertCommsTextLogReportLogs0(ctx context.Context, exec bob.Executor, publicreportReportLogs1 []*PublicreportReportLogSetter, commsTextLog0 *CommsTextLog) (PublicreportReportLogSlice, error) { for i := range publicreportReportLogs1 { publicreportReportLogs1[i].TextLogID = omitnull.From(commsTextLog0.ID) @@ -948,6 +1134,34 @@ func (o *CommsTextLog) Preload(name string, retrieved any) error { rel.R.SourceTextLogs = CommsTextLogSlice{o} } return nil + case "ResponseTextLogCommunications": + rels, ok := retrieved.(CommunicationSlice) + if !ok { + return fmt.Errorf("commsTextLog cannot load %T as %q", retrieved, name) + } + + o.R.ResponseTextLogCommunications = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ResponseTextLogTextLog = o + } + } + return nil + case "SourceTextLogCommunications": + rels, ok := retrieved.(CommunicationSlice) + if !ok { + return fmt.Errorf("commsTextLog cannot load %T as %q", retrieved, name) + } + + o.R.SourceTextLogCommunications = rels + + for _, rel := range rels { + if rel != nil { + rel.R.SourceTextLogTextLog = o + } + } + return nil case "ReportLogs": rels, ok := retrieved.(PublicreportReportLogSlice) if !ok { @@ -1018,10 +1232,12 @@ func buildCommsTextLogPreloader() commsTextLogPreloader { } type commsTextLogThenLoader[Q orm.Loadable] struct { - DestinationPhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - SourcePhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReportLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReportTexts func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + DestinationPhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SourcePhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ResponseTextLogCommunications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SourceTextLogCommunications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReportLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReportTexts func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildCommsTextLogThenLoader[Q orm.Loadable]() commsTextLogThenLoader[Q] { @@ -1031,6 +1247,12 @@ func buildCommsTextLogThenLoader[Q orm.Loadable]() commsTextLogThenLoader[Q] { type SourcePhoneLoadInterface interface { LoadSourcePhone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type ResponseTextLogCommunicationsLoadInterface interface { + LoadResponseTextLogCommunications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SourceTextLogCommunicationsLoadInterface interface { + LoadSourceTextLogCommunications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type ReportLogsLoadInterface interface { LoadReportLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -1051,6 +1273,18 @@ func buildCommsTextLogThenLoader[Q orm.Loadable]() commsTextLogThenLoader[Q] { return retrieved.LoadSourcePhone(ctx, exec, mods...) }, ), + ResponseTextLogCommunications: thenLoadBuilder[Q]( + "ResponseTextLogCommunications", + func(ctx context.Context, exec bob.Executor, retrieved ResponseTextLogCommunicationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadResponseTextLogCommunications(ctx, exec, mods...) + }, + ), + SourceTextLogCommunications: thenLoadBuilder[Q]( + "SourceTextLogCommunications", + func(ctx context.Context, exec bob.Executor, retrieved SourceTextLogCommunicationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSourceTextLogCommunications(ctx, exec, mods...) + }, + ), ReportLogs: thenLoadBuilder[Q]( "ReportLogs", func(ctx context.Context, exec bob.Executor, retrieved ReportLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -1170,6 +1404,134 @@ func (os CommsTextLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Execut return nil } +// LoadResponseTextLogCommunications loads the commsTextLog's ResponseTextLogCommunications into the .R struct +func (o *CommsTextLog) LoadResponseTextLogCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ResponseTextLogCommunications = nil + + related, err := o.ResponseTextLogCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ResponseTextLogTextLog = o + } + + o.R.ResponseTextLogCommunications = related + return nil +} + +// LoadResponseTextLogCommunications loads the commsTextLog's ResponseTextLogCommunications into the .R struct +func (os CommsTextLogSlice) LoadResponseTextLogCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + communications, err := os.ResponseTextLogCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ResponseTextLogCommunications = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range communications { + + if !rel.ResponseTextLogID.IsValue() { + continue + } + if !(rel.ResponseTextLogID.IsValue() && o.ID == rel.ResponseTextLogID.MustGet()) { + continue + } + + rel.R.ResponseTextLogTextLog = o + + o.R.ResponseTextLogCommunications = append(o.R.ResponseTextLogCommunications, rel) + } + } + + return nil +} + +// LoadSourceTextLogCommunications loads the commsTextLog's SourceTextLogCommunications into the .R struct +func (o *CommsTextLog) LoadSourceTextLogCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SourceTextLogCommunications = nil + + related, err := o.SourceTextLogCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.SourceTextLogTextLog = o + } + + o.R.SourceTextLogCommunications = related + return nil +} + +// LoadSourceTextLogCommunications loads the commsTextLog's SourceTextLogCommunications into the .R struct +func (os CommsTextLogSlice) LoadSourceTextLogCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + communications, err := os.SourceTextLogCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.SourceTextLogCommunications = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range communications { + + if !rel.SourceTextLogID.IsValue() { + continue + } + if !(rel.SourceTextLogID.IsValue() && o.ID == rel.SourceTextLogID.MustGet()) { + continue + } + + rel.R.SourceTextLogTextLog = o + + o.R.SourceTextLogCommunications = append(o.R.SourceTextLogCommunications, rel) + } + } + + return nil +} + // LoadReportLogs loads the commsTextLog's ReportLogs into the .R struct func (o *CommsTextLog) LoadReportLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { diff --git a/db/models/communication.bob.go b/db/models/communication.bob.go new file mode 100644 index 00000000..9d7e8ebb --- /dev/null +++ b/db/models/communication.bob.go @@ -0,0 +1,2215 @@ +// 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" ` + 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" ` + + 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 + 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 + 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", "response_email_log_id", "response_text_log_id", "set_pending", "set_pending_by", "source_email_log_id", "source_report_id", "source_text_log_id", + ).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"), + 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"), + } +} + +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 + ResponseEmailLogID psql.Expression + ResponseTextLogID psql.Expression + SetPending psql.Expression + SetPendingBy psql.Expression + SourceEmailLogID psql.Expression + SourceReportID psql.Expression + SourceTextLogID 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" ` + 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" ` +} + +func (s CommunicationSetter) SetColumns() []string { + vals := make([]string, 0, 15) + 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.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") + } + 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.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() + } +} + +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, 15) + 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.ResponseEmailLogID.IsUnset() { + vals[8] = psql.Arg(s.ResponseEmailLogID.MustGetNull()) + } else { + vals[8] = psql.Raw("DEFAULT") + } + + if !s.ResponseTextLogID.IsUnset() { + vals[9] = psql.Arg(s.ResponseTextLogID.MustGetNull()) + } else { + vals[9] = psql.Raw("DEFAULT") + } + + if !s.SetPending.IsUnset() { + vals[10] = psql.Arg(s.SetPending.MustGetNull()) + } else { + vals[10] = psql.Raw("DEFAULT") + } + + if !s.SetPendingBy.IsUnset() { + vals[11] = psql.Arg(s.SetPendingBy.MustGetNull()) + } else { + vals[11] = psql.Raw("DEFAULT") + } + + if !s.SourceEmailLogID.IsUnset() { + vals[12] = psql.Arg(s.SourceEmailLogID.MustGetNull()) + } else { + vals[12] = psql.Raw("DEFAULT") + } + + if !s.SourceReportID.IsUnset() { + vals[13] = psql.Arg(s.SourceReportID.MustGetNull()) + } else { + vals[13] = psql.Raw("DEFAULT") + } + + if !s.SourceTextLogID.IsUnset() { + vals[14] = psql.Arg(s.SourceTextLogID.MustGetNull()) + } else { + vals[14] = 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, 15) + + 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.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), + }}) + } + + 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)), + )...) +} + +// 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)), + )...) +} + +// 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 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 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] + 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] +} + +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), + 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), + } +} + +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 "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 "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 + ResponseEmailLogEmailLog func(...psql.PreloadOption) psql.Preloader + ResponseTextLogTextLog func(...psql.PreloadOption) psql.Preloader + SetPendingByUser 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...) + }, + 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...) + }, + 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] + 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] + 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 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 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...) + }, + ), + 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...) + }, + ), + 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 +} + +// 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 +} + +// 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 +} diff --git a/db/models/publicreport.report.bob.go b/db/models/publicreport.report.bob.go index 1481a06c..f82b6f55 100644 --- a/db/models/publicreport.report.bob.go +++ b/db/models/publicreport.report.bob.go @@ -68,20 +68,21 @@ type PublicreportReportsQuery = *psql.ViewQuery[*PublicreportReport, Publicrepor // publicreportReportR is where relationships are stored. type publicreportReportR struct { - TextJobs CommsTextJobSlice // comms.text_job.text_job_report_id_fkey - Compliance *PublicreportCompliance // publicreport.compliance.compliance_report_id_fkey - NotifyEmails PublicreportNotifyEmailSlice // publicreport.notify_email.notify_email_report_id_fkey - NotifyPhones PublicreportNotifyPhoneSlice // publicreport.notify_phone.notify_phone_report_id_fkey - Nuisance *PublicreportNuisance // publicreport.nuisance.nuisance_report_id_fkey - Address *Address // publicreport.report.report_address_id_fkey - Client *PublicreportClient // publicreport.report.report_client_uuid_fkey - Organization *Organization // publicreport.report.report_organization_id_fkey - ReviewerUser *User // publicreport.report.report_reviewer_id_fkey - Images PublicreportImageSlice // publicreport.report_image.report_image_image_id_fkeypublicreport.report_image.report_image_report_id_fkey - ReportLogs PublicreportReportLogSlice // publicreport.report_log.report_log_report_id_fkey - Water *PublicreportWater // publicreport.water.water_report_id_fkey - ReportTexts ReportTextSlice // report_text.report_text_report_id_fkey - Signals SignalSlice // signal.signal_report_id_fkey + TextJobs CommsTextJobSlice // comms.text_job.text_job_report_id_fkey + SourceReportCommunications CommunicationSlice // communication.communication_source_report_id_fkey + Compliance *PublicreportCompliance // publicreport.compliance.compliance_report_id_fkey + NotifyEmails PublicreportNotifyEmailSlice // publicreport.notify_email.notify_email_report_id_fkey + NotifyPhones PublicreportNotifyPhoneSlice // publicreport.notify_phone.notify_phone_report_id_fkey + Nuisance *PublicreportNuisance // publicreport.nuisance.nuisance_report_id_fkey + Address *Address // publicreport.report.report_address_id_fkey + Client *PublicreportClient // publicreport.report.report_client_uuid_fkey + Organization *Organization // publicreport.report.report_organization_id_fkey + ReviewerUser *User // publicreport.report.report_reviewer_id_fkey + Images PublicreportImageSlice // publicreport.report_image.report_image_image_id_fkeypublicreport.report_image.report_image_report_id_fkey + ReportLogs PublicreportReportLogSlice // publicreport.report_log.report_log_report_id_fkey + Water *PublicreportWater // publicreport.water.water_report_id_fkey + ReportTexts ReportTextSlice // report_text.report_text_report_id_fkey + Signals SignalSlice // signal.signal_report_id_fkey } func buildPublicreportReportColumns(alias string) publicreportReportColumns { @@ -876,6 +877,30 @@ func (os PublicreportReportSlice) TextJobs(mods ...bob.Mod[*dialect.SelectQuery] )...) } +// SourceReportCommunications starts a query for related objects on communication +func (o *PublicreportReport) SourceReportCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + return Communications.Query(append(mods, + sm.Where(Communications.Columns.SourceReportID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportReportSlice) SourceReportCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return Communications.Query(append(mods, + sm.Where(psql.Group(Communications.Columns.SourceReportID).OP("IN", PKArgExpr)), + )...) +} + // Compliance starts a query for related objects on publicreport.compliance func (o *PublicreportReport) Compliance(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportCompliancesQuery { return PublicreportCompliances.Query(append(mods, @@ -1261,6 +1286,74 @@ func (publicreportReport0 *PublicreportReport) AttachTextJobs(ctx context.Contex return nil } +func insertPublicreportReportSourceReportCommunications0(ctx context.Context, exec bob.Executor, communications1 []*CommunicationSetter, publicreportReport0 *PublicreportReport) (CommunicationSlice, error) { + for i := range communications1 { + communications1[i].SourceReportID = omitnull.From(publicreportReport0.ID) + } + + ret, err := Communications.Insert(bob.ToMods(communications1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportReportSourceReportCommunications0: %w", err) + } + + return ret, nil +} + +func attachPublicreportReportSourceReportCommunications0(ctx context.Context, exec bob.Executor, count int, communications1 CommunicationSlice, publicreportReport0 *PublicreportReport) (CommunicationSlice, error) { + setter := &CommunicationSetter{ + SourceReportID: omitnull.From(publicreportReport0.ID), + } + + err := communications1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportSourceReportCommunications0: %w", err) + } + + return communications1, nil +} + +func (publicreportReport0 *PublicreportReport) InsertSourceReportCommunications(ctx context.Context, exec bob.Executor, related ...*CommunicationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + communications1, err := insertPublicreportReportSourceReportCommunications0(ctx, exec, related, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.SourceReportCommunications = append(publicreportReport0.R.SourceReportCommunications, communications1...) + + for _, rel := range communications1 { + rel.R.SourceReportReport = publicreportReport0 + } + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachSourceReportCommunications(ctx context.Context, exec bob.Executor, related ...*Communication) error { + if len(related) == 0 { + return nil + } + + var err error + communications1 := CommunicationSlice(related) + + _, err = attachPublicreportReportSourceReportCommunications0(ctx, exec, len(related), communications1, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.SourceReportCommunications = append(publicreportReport0.R.SourceReportCommunications, communications1...) + + for _, rel := range related { + rel.R.SourceReportReport = publicreportReport0 + } + + return nil +} + func insertPublicreportReportCompliance0(ctx context.Context, exec bob.Executor, publicreportCompliance1 *PublicreportComplianceSetter, publicreportReport0 *PublicreportReport) (*PublicreportCompliance, error) { publicreportCompliance1.ReportID = omit.From(publicreportReport0.ID) @@ -2100,6 +2193,20 @@ func (o *PublicreportReport) Preload(name string, retrieved any) error { } } return nil + case "SourceReportCommunications": + rels, ok := retrieved.(CommunicationSlice) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.SourceReportCommunications = rels + + for _, rel := range rels { + if rel != nil { + rel.R.SourceReportReport = o + } + } + return nil case "Compliance": rel, ok := retrieved.(*PublicreportCompliance) if !ok { @@ -2380,26 +2487,30 @@ func buildPublicreportReportPreloader() publicreportReportPreloader { } type publicreportReportThenLoader[Q orm.Loadable] struct { - TextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Compliance func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - NotifyEmails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - NotifyPhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Nuisance func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Address func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Client func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReviewerUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReportLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Water func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReportTexts func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Signals func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + TextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SourceReportCommunications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Compliance func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + NotifyEmails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + NotifyPhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Nuisance func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Address func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Client func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReviewerUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReportLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Water func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReportTexts func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Signals func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildPublicreportReportThenLoader[Q orm.Loadable]() publicreportReportThenLoader[Q] { type TextJobsLoadInterface interface { LoadTextJobs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type SourceReportCommunicationsLoadInterface interface { + LoadSourceReportCommunications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type ComplianceLoadInterface interface { LoadCompliance(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -2447,6 +2558,12 @@ func buildPublicreportReportThenLoader[Q orm.Loadable]() publicreportReportThenL return retrieved.LoadTextJobs(ctx, exec, mods...) }, ), + SourceReportCommunications: thenLoadBuilder[Q]( + "SourceReportCommunications", + func(ctx context.Context, exec bob.Executor, retrieved SourceReportCommunicationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSourceReportCommunications(ctx, exec, mods...) + }, + ), Compliance: thenLoadBuilder[Q]( "Compliance", func(ctx context.Context, exec bob.Executor, retrieved ComplianceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -2592,6 +2709,70 @@ func (os PublicreportReportSlice) LoadTextJobs(ctx context.Context, exec bob.Exe return nil } +// LoadSourceReportCommunications loads the publicreportReport's SourceReportCommunications into the .R struct +func (o *PublicreportReport) LoadSourceReportCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SourceReportCommunications = nil + + related, err := o.SourceReportCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.SourceReportReport = o + } + + o.R.SourceReportCommunications = related + return nil +} + +// LoadSourceReportCommunications loads the publicreportReport's SourceReportCommunications into the .R struct +func (os PublicreportReportSlice) LoadSourceReportCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + communications, err := os.SourceReportCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.SourceReportCommunications = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range communications { + + if !rel.SourceReportID.IsValue() { + continue + } + if !(rel.SourceReportID.IsValue() && o.ID == rel.SourceReportID.MustGet()) { + continue + } + + rel.R.SourceReportReport = o + + o.R.SourceReportCommunications = append(o.R.SourceReportCommunications, rel) + } + } + + return nil +} + // LoadCompliance loads the publicreportReport's Compliance into the .R struct func (o *PublicreportReport) LoadCompliance(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { diff --git a/db/models/user_.bob.go b/db/models/user_.bob.go index a469bdaf..4a04e4ab 100644 --- a/db/models/user_.bob.go +++ b/db/models/user_.bob.go @@ -63,6 +63,10 @@ type userR struct { UserOauthTokens ArcgisOauthTokenSlice // arcgis.oauth_token.oauth_token_user_id_fkey PublicUserUser ArcgisUserSlice // arcgis.user_.user__public_user_id_fkey CreatorTextJobs CommsTextJobSlice // comms.text_job.text_job_creator_id_fkey + ClosedByCommunications CommunicationSlice // communication.communication_closed_by_fkey + InvalidatedByCommunications CommunicationSlice // communication.communication_invalidated_by_fkey + OpenedByCommunications CommunicationSlice // communication.communication_opened_by_fkey + SetPendingByCommunications CommunicationSlice // communication.communication_set_pending_by_fkey CreatorComplianceReportRequests ComplianceReportRequestSlice // compliance_report_request.compliance_report_request_creator_fkey CreatorFeatures FeatureSlice // feature.feature_creator_id_fkey CommitterFiles FileuploadFileSlice // fileupload.file.file_committer_fkey @@ -816,6 +820,102 @@ func (os UserSlice) CreatorTextJobs(mods ...bob.Mod[*dialect.SelectQuery]) Comms )...) } +// ClosedByCommunications starts a query for related objects on communication +func (o *User) ClosedByCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + return Communications.Query(append(mods, + sm.Where(Communications.Columns.ClosedBy.EQ(psql.Arg(o.ID))), + )...) +} + +func (os UserSlice) ClosedByCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return Communications.Query(append(mods, + sm.Where(psql.Group(Communications.Columns.ClosedBy).OP("IN", PKArgExpr)), + )...) +} + +// InvalidatedByCommunications starts a query for related objects on communication +func (o *User) InvalidatedByCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + return Communications.Query(append(mods, + sm.Where(Communications.Columns.InvalidatedBy.EQ(psql.Arg(o.ID))), + )...) +} + +func (os UserSlice) InvalidatedByCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return Communications.Query(append(mods, + sm.Where(psql.Group(Communications.Columns.InvalidatedBy).OP("IN", PKArgExpr)), + )...) +} + +// OpenedByCommunications starts a query for related objects on communication +func (o *User) OpenedByCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + return Communications.Query(append(mods, + sm.Where(Communications.Columns.OpenedBy.EQ(psql.Arg(o.ID))), + )...) +} + +func (os UserSlice) OpenedByCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return Communications.Query(append(mods, + sm.Where(psql.Group(Communications.Columns.OpenedBy).OP("IN", PKArgExpr)), + )...) +} + +// SetPendingByCommunications starts a query for related objects on communication +func (o *User) SetPendingByCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + return Communications.Query(append(mods, + sm.Where(Communications.Columns.SetPendingBy.EQ(psql.Arg(o.ID))), + )...) +} + +func (os UserSlice) SetPendingByCommunications(mods ...bob.Mod[*dialect.SelectQuery]) CommunicationsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return Communications.Query(append(mods, + sm.Where(psql.Group(Communications.Columns.SetPendingBy).OP("IN", PKArgExpr)), + )...) +} + // CreatorComplianceReportRequests starts a query for related objects on compliance_report_request func (o *User) CreatorComplianceReportRequests(mods ...bob.Mod[*dialect.SelectQuery]) ComplianceReportRequestsQuery { return ComplianceReportRequests.Query(append(mods, @@ -1620,6 +1720,278 @@ func (user0 *User) AttachCreatorTextJobs(ctx context.Context, exec bob.Executor, return nil } +func insertUserClosedByCommunications0(ctx context.Context, exec bob.Executor, communications1 []*CommunicationSetter, user0 *User) (CommunicationSlice, error) { + for i := range communications1 { + communications1[i].ClosedBy = omitnull.From(user0.ID) + } + + ret, err := Communications.Insert(bob.ToMods(communications1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertUserClosedByCommunications0: %w", err) + } + + return ret, nil +} + +func attachUserClosedByCommunications0(ctx context.Context, exec bob.Executor, count int, communications1 CommunicationSlice, user0 *User) (CommunicationSlice, error) { + setter := &CommunicationSetter{ + ClosedBy: omitnull.From(user0.ID), + } + + err := communications1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachUserClosedByCommunications0: %w", err) + } + + return communications1, nil +} + +func (user0 *User) InsertClosedByCommunications(ctx context.Context, exec bob.Executor, related ...*CommunicationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + communications1, err := insertUserClosedByCommunications0(ctx, exec, related, user0) + if err != nil { + return err + } + + user0.R.ClosedByCommunications = append(user0.R.ClosedByCommunications, communications1...) + + for _, rel := range communications1 { + rel.R.ClosedByUser = user0 + } + return nil +} + +func (user0 *User) AttachClosedByCommunications(ctx context.Context, exec bob.Executor, related ...*Communication) error { + if len(related) == 0 { + return nil + } + + var err error + communications1 := CommunicationSlice(related) + + _, err = attachUserClosedByCommunications0(ctx, exec, len(related), communications1, user0) + if err != nil { + return err + } + + user0.R.ClosedByCommunications = append(user0.R.ClosedByCommunications, communications1...) + + for _, rel := range related { + rel.R.ClosedByUser = user0 + } + + return nil +} + +func insertUserInvalidatedByCommunications0(ctx context.Context, exec bob.Executor, communications1 []*CommunicationSetter, user0 *User) (CommunicationSlice, error) { + for i := range communications1 { + communications1[i].InvalidatedBy = omitnull.From(user0.ID) + } + + ret, err := Communications.Insert(bob.ToMods(communications1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertUserInvalidatedByCommunications0: %w", err) + } + + return ret, nil +} + +func attachUserInvalidatedByCommunications0(ctx context.Context, exec bob.Executor, count int, communications1 CommunicationSlice, user0 *User) (CommunicationSlice, error) { + setter := &CommunicationSetter{ + InvalidatedBy: omitnull.From(user0.ID), + } + + err := communications1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachUserInvalidatedByCommunications0: %w", err) + } + + return communications1, nil +} + +func (user0 *User) InsertInvalidatedByCommunications(ctx context.Context, exec bob.Executor, related ...*CommunicationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + communications1, err := insertUserInvalidatedByCommunications0(ctx, exec, related, user0) + if err != nil { + return err + } + + user0.R.InvalidatedByCommunications = append(user0.R.InvalidatedByCommunications, communications1...) + + for _, rel := range communications1 { + rel.R.InvalidatedByUser = user0 + } + return nil +} + +func (user0 *User) AttachInvalidatedByCommunications(ctx context.Context, exec bob.Executor, related ...*Communication) error { + if len(related) == 0 { + return nil + } + + var err error + communications1 := CommunicationSlice(related) + + _, err = attachUserInvalidatedByCommunications0(ctx, exec, len(related), communications1, user0) + if err != nil { + return err + } + + user0.R.InvalidatedByCommunications = append(user0.R.InvalidatedByCommunications, communications1...) + + for _, rel := range related { + rel.R.InvalidatedByUser = user0 + } + + return nil +} + +func insertUserOpenedByCommunications0(ctx context.Context, exec bob.Executor, communications1 []*CommunicationSetter, user0 *User) (CommunicationSlice, error) { + for i := range communications1 { + communications1[i].OpenedBy = omitnull.From(user0.ID) + } + + ret, err := Communications.Insert(bob.ToMods(communications1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertUserOpenedByCommunications0: %w", err) + } + + return ret, nil +} + +func attachUserOpenedByCommunications0(ctx context.Context, exec bob.Executor, count int, communications1 CommunicationSlice, user0 *User) (CommunicationSlice, error) { + setter := &CommunicationSetter{ + OpenedBy: omitnull.From(user0.ID), + } + + err := communications1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachUserOpenedByCommunications0: %w", err) + } + + return communications1, nil +} + +func (user0 *User) InsertOpenedByCommunications(ctx context.Context, exec bob.Executor, related ...*CommunicationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + communications1, err := insertUserOpenedByCommunications0(ctx, exec, related, user0) + if err != nil { + return err + } + + user0.R.OpenedByCommunications = append(user0.R.OpenedByCommunications, communications1...) + + for _, rel := range communications1 { + rel.R.OpenedByUser = user0 + } + return nil +} + +func (user0 *User) AttachOpenedByCommunications(ctx context.Context, exec bob.Executor, related ...*Communication) error { + if len(related) == 0 { + return nil + } + + var err error + communications1 := CommunicationSlice(related) + + _, err = attachUserOpenedByCommunications0(ctx, exec, len(related), communications1, user0) + if err != nil { + return err + } + + user0.R.OpenedByCommunications = append(user0.R.OpenedByCommunications, communications1...) + + for _, rel := range related { + rel.R.OpenedByUser = user0 + } + + return nil +} + +func insertUserSetPendingByCommunications0(ctx context.Context, exec bob.Executor, communications1 []*CommunicationSetter, user0 *User) (CommunicationSlice, error) { + for i := range communications1 { + communications1[i].SetPendingBy = omitnull.From(user0.ID) + } + + ret, err := Communications.Insert(bob.ToMods(communications1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertUserSetPendingByCommunications0: %w", err) + } + + return ret, nil +} + +func attachUserSetPendingByCommunications0(ctx context.Context, exec bob.Executor, count int, communications1 CommunicationSlice, user0 *User) (CommunicationSlice, error) { + setter := &CommunicationSetter{ + SetPendingBy: omitnull.From(user0.ID), + } + + err := communications1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachUserSetPendingByCommunications0: %w", err) + } + + return communications1, nil +} + +func (user0 *User) InsertSetPendingByCommunications(ctx context.Context, exec bob.Executor, related ...*CommunicationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + communications1, err := insertUserSetPendingByCommunications0(ctx, exec, related, user0) + if err != nil { + return err + } + + user0.R.SetPendingByCommunications = append(user0.R.SetPendingByCommunications, communications1...) + + for _, rel := range communications1 { + rel.R.SetPendingByUser = user0 + } + return nil +} + +func (user0 *User) AttachSetPendingByCommunications(ctx context.Context, exec bob.Executor, related ...*Communication) error { + if len(related) == 0 { + return nil + } + + var err error + communications1 := CommunicationSlice(related) + + _, err = attachUserSetPendingByCommunications0(ctx, exec, len(related), communications1, user0) + if err != nil { + return err + } + + user0.R.SetPendingByCommunications = append(user0.R.SetPendingByCommunications, communications1...) + + for _, rel := range related { + rel.R.SetPendingByUser = user0 + } + + return nil +} + func insertUserCreatorComplianceReportRequests0(ctx context.Context, exec bob.Executor, complianceReportRequests1 []*ComplianceReportRequestSetter, user0 *User) (ComplianceReportRequestSlice, error) { for i := range complianceReportRequests1 { complianceReportRequests1[i].Creator = omit.From(user0.ID) @@ -3394,6 +3766,62 @@ func (o *User) Preload(name string, retrieved any) error { } } return nil + case "ClosedByCommunications": + rels, ok := retrieved.(CommunicationSlice) + if !ok { + return fmt.Errorf("user cannot load %T as %q", retrieved, name) + } + + o.R.ClosedByCommunications = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ClosedByUser = o + } + } + return nil + case "InvalidatedByCommunications": + rels, ok := retrieved.(CommunicationSlice) + if !ok { + return fmt.Errorf("user cannot load %T as %q", retrieved, name) + } + + o.R.InvalidatedByCommunications = rels + + for _, rel := range rels { + if rel != nil { + rel.R.InvalidatedByUser = o + } + } + return nil + case "OpenedByCommunications": + rels, ok := retrieved.(CommunicationSlice) + if !ok { + return fmt.Errorf("user cannot load %T as %q", retrieved, name) + } + + o.R.OpenedByCommunications = rels + + for _, rel := range rels { + if rel != nil { + rel.R.OpenedByUser = o + } + } + return nil + case "SetPendingByCommunications": + rels, ok := retrieved.(CommunicationSlice) + if !ok { + return fmt.Errorf("user cannot load %T as %q", retrieved, name) + } + + o.R.SetPendingByCommunications = rels + + for _, rel := range rels { + if rel != nil { + rel.R.SetPendingByUser = o + } + } + return nil case "CreatorComplianceReportRequests": rels, ok := retrieved.(ComplianceReportRequestSlice) if !ok { @@ -3773,6 +4201,10 @@ type userThenLoader[Q orm.Loadable] struct { UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorTextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ClosedByCommunications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + InvalidatedByCommunications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + OpenedByCommunications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SetPendingByCommunications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorComplianceReportRequests func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorFeatures func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CommitterFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] @@ -3810,6 +4242,18 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { type CreatorTextJobsLoadInterface interface { LoadCreatorTextJobs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type ClosedByCommunicationsLoadInterface interface { + LoadClosedByCommunications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type InvalidatedByCommunicationsLoadInterface interface { + LoadInvalidatedByCommunications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type OpenedByCommunicationsLoadInterface interface { + LoadOpenedByCommunications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SetPendingByCommunicationsLoadInterface interface { + LoadSetPendingByCommunications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type CreatorComplianceReportRequestsLoadInterface interface { LoadCreatorComplianceReportRequests(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -3905,6 +4349,30 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { return retrieved.LoadCreatorTextJobs(ctx, exec, mods...) }, ), + ClosedByCommunications: thenLoadBuilder[Q]( + "ClosedByCommunications", + func(ctx context.Context, exec bob.Executor, retrieved ClosedByCommunicationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadClosedByCommunications(ctx, exec, mods...) + }, + ), + InvalidatedByCommunications: thenLoadBuilder[Q]( + "InvalidatedByCommunications", + func(ctx context.Context, exec bob.Executor, retrieved InvalidatedByCommunicationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadInvalidatedByCommunications(ctx, exec, mods...) + }, + ), + OpenedByCommunications: thenLoadBuilder[Q]( + "OpenedByCommunications", + func(ctx context.Context, exec bob.Executor, retrieved OpenedByCommunicationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadOpenedByCommunications(ctx, exec, mods...) + }, + ), + SetPendingByCommunications: thenLoadBuilder[Q]( + "SetPendingByCommunications", + func(ctx context.Context, exec bob.Executor, retrieved SetPendingByCommunicationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSetPendingByCommunications(ctx, exec, mods...) + }, + ), CreatorComplianceReportRequests: thenLoadBuilder[Q]( "CreatorComplianceReportRequests", func(ctx context.Context, exec bob.Executor, retrieved CreatorComplianceReportRequestsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -4244,6 +4712,262 @@ func (os UserSlice) LoadCreatorTextJobs(ctx context.Context, exec bob.Executor, return nil } +// LoadClosedByCommunications loads the user's ClosedByCommunications into the .R struct +func (o *User) LoadClosedByCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ClosedByCommunications = nil + + related, err := o.ClosedByCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ClosedByUser = o + } + + o.R.ClosedByCommunications = related + return nil +} + +// LoadClosedByCommunications loads the user's ClosedByCommunications into the .R struct +func (os UserSlice) LoadClosedByCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + communications, err := os.ClosedByCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ClosedByCommunications = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range communications { + + if !rel.ClosedBy.IsValue() { + continue + } + if !(rel.ClosedBy.IsValue() && o.ID == rel.ClosedBy.MustGet()) { + continue + } + + rel.R.ClosedByUser = o + + o.R.ClosedByCommunications = append(o.R.ClosedByCommunications, rel) + } + } + + return nil +} + +// LoadInvalidatedByCommunications loads the user's InvalidatedByCommunications into the .R struct +func (o *User) LoadInvalidatedByCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.InvalidatedByCommunications = nil + + related, err := o.InvalidatedByCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.InvalidatedByUser = o + } + + o.R.InvalidatedByCommunications = related + return nil +} + +// LoadInvalidatedByCommunications loads the user's InvalidatedByCommunications into the .R struct +func (os UserSlice) LoadInvalidatedByCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + communications, err := os.InvalidatedByCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.InvalidatedByCommunications = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range communications { + + if !rel.InvalidatedBy.IsValue() { + continue + } + if !(rel.InvalidatedBy.IsValue() && o.ID == rel.InvalidatedBy.MustGet()) { + continue + } + + rel.R.InvalidatedByUser = o + + o.R.InvalidatedByCommunications = append(o.R.InvalidatedByCommunications, rel) + } + } + + return nil +} + +// LoadOpenedByCommunications loads the user's OpenedByCommunications into the .R struct +func (o *User) LoadOpenedByCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.OpenedByCommunications = nil + + related, err := o.OpenedByCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.OpenedByUser = o + } + + o.R.OpenedByCommunications = related + return nil +} + +// LoadOpenedByCommunications loads the user's OpenedByCommunications into the .R struct +func (os UserSlice) LoadOpenedByCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + communications, err := os.OpenedByCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.OpenedByCommunications = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range communications { + + if !rel.OpenedBy.IsValue() { + continue + } + if !(rel.OpenedBy.IsValue() && o.ID == rel.OpenedBy.MustGet()) { + continue + } + + rel.R.OpenedByUser = o + + o.R.OpenedByCommunications = append(o.R.OpenedByCommunications, rel) + } + } + + return nil +} + +// LoadSetPendingByCommunications loads the user's SetPendingByCommunications into the .R struct +func (o *User) LoadSetPendingByCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SetPendingByCommunications = nil + + related, err := o.SetPendingByCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.SetPendingByUser = o + } + + o.R.SetPendingByCommunications = related + return nil +} + +// LoadSetPendingByCommunications loads the user's SetPendingByCommunications into the .R struct +func (os UserSlice) LoadSetPendingByCommunications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + communications, err := os.SetPendingByCommunications(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.SetPendingByCommunications = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range communications { + + if !rel.SetPendingBy.IsValue() { + continue + } + if !(rel.SetPendingBy.IsValue() && o.ID == rel.SetPendingBy.MustGet()) { + continue + } + + rel.R.SetPendingByUser = o + + o.R.SetPendingByCommunications = append(o.R.SetPendingByCommunications, rel) + } + } + + return nil +} + // LoadCreatorComplianceReportRequests loads the user's CreatorComplianceReportRequests into the .R struct func (o *User) LoadCreatorComplianceReportRequests(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil {