func (o *County) AddPollsCounties(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*PollsCounty) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.CountyID = o.CountyID
			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_county\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"county_id"}),
				strmangle.WhereClause("\"", "\"", 2, pollsCountyPrimaryKeyColumns),
			)
			values := []interface{}{o.CountyID, rel.PollCountyID}

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

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

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &pollsCountyR{
				County: o,
			}
		} else {
			rel.R.County = o
		}
	}
	return nil
}
// AddPollsCounties adds the given related objects to the existing relationships
// of the county, optionally inserting them as new records.
// Appends related to o.R.PollsCounties.
// Sets related.R.County appropriately.
AddPollsCounties adds the given related objects to the existing relationships
of the county, optionally inserting them as new records.
Appends related to o.R.PollsCounties.
Sets related.R.County appropriately.
// AddPollsCounties adds the given related objects to the existing relationships // of the county optionally inserting them as new records . // Appends related to o . R . PollsCounties . // Sets related . R . County appropriately .
func (o *County) AddPollsCounties(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*PollsCounty) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.CountyID = o.CountyID
			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_county\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"county_id"}),
				strmangle.WhereClause("\"", "\"", 2, pollsCountyPrimaryKeyColumns),
			)
			values := []interface{}{o.CountyID, rel.PollCountyID}
			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.CountyID = o.CountyID
		}
	}
	if o.R == nil {
		o.R = &countyR{
			PollsCounties: related,
		}
	} else {
		o.R.PollsCounties = append(o.R.PollsCounties, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &pollsCountyR{
				County: o,
			}
		} else {
			rel.R.County = o
		}
	}
	return nil
}
func ( o * County ) AddPollsCounties ( ctx context . Context , exec boil . ContextExecutor , insert bool , related ... * PollsCounty ) error { var err error for _ , rel := range related { if insert { rel . CountyID = o . CountyID 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 , pollsCountyPrimaryKeyColumns ) , ) values := [ ] interface { } { o . CountyID , rel . PollCountyID } 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 . CountyID = o . CountyID } } if o . R == nil { o . R = & countyR { PollsCounties : related , } } else { o . R . PollsCounties = append ( o . R . PollsCounties , related ... ) } for _ , rel := range related { if rel . R == nil { rel . R = & pollsCountyR { County : o , } } else { rel . R . County = o } } return nil }
AddPollsCounties adds the given related objects to the existing relationships
of the county, optionally inserting them as new records.
AddPollsCounties adds the given related objects to the existing relationships of the county optionally inserting them as new records .