func (o *Message) AddMessagesLinks(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*MessagesLink) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.MessageID = o.MessageID
			if err = rel.Insert(ctx, exec, boil.Infer()); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"messages_links\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"message_id"}),
				strmangle.WhereClause("\"", "\"", 2, messagesLinkPrimaryKeyColumns),
			)
			values := []interface{}{o.MessageID, rel.MessageLinkID}

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

			if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
				return errors.Wrap(err, "failed to update foreign table")
			}

			rel.MessageID = o.MessageID
		}
	}

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

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &messagesLinkR{
				Message: o,
			}
		} else {
			rel.R.Message = o
		}
	}
	return nil
}
// AddMessagesLinks adds the given related objects to the existing relationships
// of the message, optionally inserting them as new records.
// Appends related to o.R.MessagesLinks.
// Sets related.R.Message appropriately.
AddMessagesLinks adds the given related objects to the existing relationships
of the message, optionally inserting them as new records.
Appends related to o.R.MessagesLinks.
Sets related.R.Message appropriately.
// AddMessagesLinks adds the given related objects to the existing relationships // of the message optionally inserting them as new records . // Appends related to o . R . MessagesLinks . // Sets related . R . Message appropriately .
func (o *Message) AddMessagesLinks(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*MessagesLink) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.MessageID = o.MessageID
			if err = rel.Insert(ctx, exec, boil.Infer()); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"messages_links\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"message_id"}),
				strmangle.WhereClause("\"", "\"", 2, messagesLinkPrimaryKeyColumns),
			)
			values := []interface{}{o.MessageID, rel.MessageLinkID}
			if boil.DebugMode {
				fmt.Fprintln(boil.DebugWriter, updateQuery)
				fmt.Fprintln(boil.DebugWriter, values)
			}
			if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
				return errors.Wrap(err, "failed to update foreign table")
			}
			rel.MessageID = o.MessageID
		}
	}
	if o.R == nil {
		o.R = &messageR{
			MessagesLinks: related,
		}
	} else {
		o.R.MessagesLinks = append(o.R.MessagesLinks, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &messagesLinkR{
				Message: o,
			}
		} else {
			rel.R.Message = o
		}
	}
	return nil
}
func ( o * Message ) AddMessagesLinks ( ctx context . Context , exec boil . ContextExecutor , insert bool , related ... * MessagesLink ) error { var err error for _ , rel := range related { if insert { rel . MessageID = o . MessageID if err = rel . Insert ( ctx , exec , boil . Infer ( ) ) ; err != nil { return errors . Wrap ( err , " " ) } } else { updateQuery := fmt . Sprintf ( " \" \" " , strmangle . SetParamNames ( " \" " , " \" " , 1 , [ ] string { " " } ) , strmangle . WhereClause ( " \" " , " \" " , 2 , messagesLinkPrimaryKeyColumns ) , ) values := [ ] interface { } { o . MessageID , rel . MessageLinkID } if boil . DebugMode { fmt . Fprintln ( boil . DebugWriter , updateQuery ) fmt . Fprintln ( boil . DebugWriter , values ) } if _ , err = exec . ExecContext ( ctx , updateQuery , values ... ) ; err != nil { return errors . Wrap ( err , " " ) } rel . MessageID = o . MessageID } } if o . R == nil { o . R = & messageR { MessagesLinks : related , } } else { o . R . MessagesLinks = append ( o . R . MessagesLinks , related ... ) } for _ , rel := range related { if rel . R == nil { rel . R = & messagesLinkR { Message : o , } } else { rel . R . Message = o } } return nil }
AddMessagesLinks adds the given related objects to the existing relationships
of the message, optionally inserting them as new records.
AddMessagesLinks adds the given related objects to the existing relationships of the message optionally inserting them as new records .