func (o *Poll) AddPollsTowns(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*PollsTown) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.PollID = o.PollID
			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 \"polls_town\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"poll_id"}),
				strmangle.WhereClause("\"", "\"", 2, pollsTownPrimaryKeyColumns),
			)
			values := []interface{}{o.PollID, rel.PollTownID}

			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.PollID = o.PollID
		}
	}

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

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &pollsTownR{
				Poll: o,
			}
		} else {
			rel.R.Poll = o
		}
	}
	return nil
}
// AddPollsTowns adds the given related objects to the existing relationships
// of the poll, optionally inserting them as new records.
// Appends related to o.R.PollsTowns.
// Sets related.R.Poll appropriately.
AddPollsTowns adds the given related objects to the existing relationships
of the poll, optionally inserting them as new records.
Appends related to o.R.PollsTowns.
Sets related.R.Poll appropriately.
// AddPollsTowns adds the given related objects to the existing relationships // of the poll optionally inserting them as new records . // Appends related to o . R . PollsTowns . // Sets related . R . Poll appropriately .
func (o *Poll) AddPollsTowns(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*PollsTown) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.PollID = o.PollID
			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 \"polls_town\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"poll_id"}),
				strmangle.WhereClause("\"", "\"", 2, pollsTownPrimaryKeyColumns),
			)
			values := []interface{}{o.PollID, rel.PollTownID}
			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.PollID = o.PollID
		}
	}
	if o.R == nil {
		o.R = &pollR{
			PollsTowns: related,
		}
	} else {
		o.R.PollsTowns = append(o.R.PollsTowns, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &pollsTownR{
				Poll: o,
			}
		} else {
			rel.R.Poll = o
		}
	}
	return nil
}
func ( o * Poll ) AddPollsTowns ( ctx context . Context , exec boil . ContextExecutor , insert bool , related ... * PollsTown ) error { var err error for _ , rel := range related { if insert { rel . PollID = o . PollID 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 , pollsTownPrimaryKeyColumns ) , ) values := [ ] interface { } { o . PollID , rel . PollTownID } 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 . PollID = o . PollID } } if o . R == nil { o . R = & pollR { PollsTowns : related , } } else { o . R . PollsTowns = append ( o . R . PollsTowns , related ... ) } for _ , rel := range related { if rel . R == nil { rel . R = & pollsTownR { Poll : o , } } else { rel . R . Poll = o } } return nil }
AddPollsTowns adds the given related objects to the existing relationships
of the poll, optionally inserting them as new records.
AddPollsTowns adds the given related objects to the existing relationships of the poll optionally inserting them as new records .