func (o *Country) AddPollsCountries(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*PollsCountry) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.CountryID = o.CountryID
			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_country\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"country_id"}),
				strmangle.WhereClause("\"", "\"", 2, pollsCountryPrimaryKeyColumns),
			)
			values := []interface{}{o.CountryID, rel.PollCountryID}

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

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

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &pollsCountryR{
				Country: o,
			}
		} else {
			rel.R.Country = o
		}
	}
	return nil
}
// AddPollsCountries adds the given related objects to the existing relationships
// of the country, optionally inserting them as new records.
// Appends related to o.R.PollsCountries.
// Sets related.R.Country appropriately.
AddPollsCountries adds the given related objects to the existing relationships
of the country, optionally inserting them as new records.
Appends related to o.R.PollsCountries.
Sets related.R.Country appropriately.
// AddPollsCountries adds the given related objects to the existing relationships // of the country optionally inserting them as new records . // Appends related to o . R . PollsCountries . // Sets related . R . Country appropriately .
func (o *Country) AddPollsCountries(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*PollsCountry) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.CountryID = o.CountryID
			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_country\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"country_id"}),
				strmangle.WhereClause("\"", "\"", 2, pollsCountryPrimaryKeyColumns),
			)
			values := []interface{}{o.CountryID, rel.PollCountryID}
			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.CountryID = o.CountryID
		}
	}
	if o.R == nil {
		o.R = &countryR{
			PollsCountries: related,
		}
	} else {
		o.R.PollsCountries = append(o.R.PollsCountries, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &pollsCountryR{
				Country: o,
			}
		} else {
			rel.R.Country = o
		}
	}
	return nil
}
func ( o * Country ) AddPollsCountries ( ctx context . Context , exec boil . ContextExecutor , insert bool , related ... * PollsCountry ) error { var err error for _ , rel := range related { if insert { rel . CountryID = o . CountryID 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 , pollsCountryPrimaryKeyColumns ) , ) values := [ ] interface { } { o . CountryID , rel . PollCountryID } 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 . CountryID = o . CountryID } } if o . R == nil { o . R = & countryR { PollsCountries : related , } } else { o . R . PollsCountries = append ( o . R . PollsCountries , related ... ) } for _ , rel := range related { if rel . R == nil { rel . R = & pollsCountryR { Country : o , } } else { rel . R . Country = o } } return nil }
AddPollsCountries adds the given related objects to the existing relationships
of the country, optionally inserting them as new records.
AddPollsCountries adds the given related objects to the existing relationships of the country optionally inserting them as new records .