func (o *Timezone) AddStates(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*State) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.TimezoneID = o.TimezoneID
			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 \"state\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"timezone_id"}),
				strmangle.WhereClause("\"", "\"", 2, statePrimaryKeyColumns),
			)
			values := []interface{}{o.TimezoneID, rel.StateID}

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

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

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &stateR{
				Timezone: o,
			}
		} else {
			rel.R.Timezone = o
		}
	}
	return nil
}
// AddStates adds the given related objects to the existing relationships
// of the timezone, optionally inserting them as new records.
// Appends related to o.R.States.
// Sets related.R.Timezone appropriately.
AddStates adds the given related objects to the existing relationships
of the timezone, optionally inserting them as new records.
Appends related to o.R.States.
Sets related.R.Timezone appropriately.
// AddStates adds the given related objects to the existing relationships // of the timezone optionally inserting them as new records . // Appends related to o . R . States . // Sets related . R . Timezone appropriately .
func (o *Timezone) AddStates(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*State) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.TimezoneID = o.TimezoneID
			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 \"state\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"timezone_id"}),
				strmangle.WhereClause("\"", "\"", 2, statePrimaryKeyColumns),
			)
			values := []interface{}{o.TimezoneID, rel.StateID}
			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.TimezoneID = o.TimezoneID
		}
	}
	if o.R == nil {
		o.R = &timezoneR{
			States: related,
		}
	} else {
		o.R.States = append(o.R.States, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &stateR{
				Timezone: o,
			}
		} else {
			rel.R.Timezone = o
		}
	}
	return nil
}
func ( o * Timezone ) AddStates ( ctx context . Context , exec boil . ContextExecutor , insert bool , related ... * State ) error { var err error for _ , rel := range related { if insert { rel . TimezoneID = o . TimezoneID 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 , statePrimaryKeyColumns ) , ) values := [ ] interface { } { o . TimezoneID , rel . StateID } 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 . TimezoneID = o . TimezoneID } } if o . R == nil { o . R = & timezoneR { States : related , } } else { o . R . States = append ( o . R . States , related ... ) } for _ , rel := range related { if rel . R == nil { rel . R = & stateR { Timezone : o , } } else { rel . R . Timezone = o } } return nil }
AddStates adds the given related objects to the existing relationships
of the timezone, optionally inserting them as new records.
AddStates adds the given related objects to the existing relationships of the timezone optionally inserting them as new records .