func (o *Town) AddSuburbs(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Suburb) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.TownID = o.TownID
			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 \"suburb\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"town_id"}),
				strmangle.WhereClause("\"", "\"", 2, suburbPrimaryKeyColumns),
			)
			values := []interface{}{o.TownID, rel.SuburbID}

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

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

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &suburbR{
				Town: o,
			}
		} else {
			rel.R.Town = o
		}
	}
	return nil
}
// AddSuburbs adds the given related objects to the existing relationships
// of the town, optionally inserting them as new records.
// Appends related to o.R.Suburbs.
// Sets related.R.Town appropriately.
AddSuburbs adds the given related objects to the existing relationships
of the town, optionally inserting them as new records.
Appends related to o.R.Suburbs.
Sets related.R.Town appropriately.
// AddSuburbs adds the given related objects to the existing relationships // of the town optionally inserting them as new records . // Appends related to o . R . Suburbs . // Sets related . R . Town appropriately .
func (o *Town) AddSuburbs(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Suburb) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.TownID = o.TownID
			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 \"suburb\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"town_id"}),
				strmangle.WhereClause("\"", "\"", 2, suburbPrimaryKeyColumns),
			)
			values := []interface{}{o.TownID, rel.SuburbID}
			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.TownID = o.TownID
		}
	}
	if o.R == nil {
		o.R = &townR{
			Suburbs: related,
		}
	} else {
		o.R.Suburbs = append(o.R.Suburbs, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &suburbR{
				Town: o,
			}
		} else {
			rel.R.Town = o
		}
	}
	return nil
}
func ( o * Town ) AddSuburbs ( ctx context . Context , exec boil . ContextExecutor , insert bool , related ... * Suburb ) error { var err error for _ , rel := range related { if insert { rel . TownID = o . TownID 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 , suburbPrimaryKeyColumns ) , ) values := [ ] interface { } { o . TownID , rel . SuburbID } 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 . TownID = o . TownID } } if o . R == nil { o . R = & townR { Suburbs : related , } } else { o . R . Suburbs = append ( o . R . Suburbs , related ... ) } for _ , rel := range related { if rel . R == nil { rel . R = & suburbR { Town : o , } } else { rel . R . Town = o } } return nil }
AddSuburbs adds the given related objects to the existing relationships
of the town, optionally inserting them as new records.
AddSuburbs adds the given related objects to the existing relationships of the town optionally inserting them as new records .