func (o *Position) AddFactorPositions(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*FactorPosition) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.PositionID = o.PositionID
			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 \"factor_positions\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"position_id"}),
				strmangle.WhereClause("\"", "\"", 2, factorPositionPrimaryKeyColumns),
			)
			values := []interface{}{o.PositionID, rel.FactorPositionID}

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

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

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &factorPositionR{
				Position: o,
			}
		} else {
			rel.R.Position = o
		}
	}
	return nil
}
// AddFactorPositions adds the given related objects to the existing relationships
// of the position, optionally inserting them as new records.
// Appends related to o.R.FactorPositions.
// Sets related.R.Position appropriately.
AddFactorPositions adds the given related objects to the existing relationships
of the position, optionally inserting them as new records.
Appends related to o.R.FactorPositions.
Sets related.R.Position appropriately.
// AddFactorPositions adds the given related objects to the existing relationships // of the position optionally inserting them as new records . // Appends related to o . R . FactorPositions . // Sets related . R . Position appropriately .
func (o *Position) AddFactorPositions(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*FactorPosition) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.PositionID = o.PositionID
			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 \"factor_positions\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"position_id"}),
				strmangle.WhereClause("\"", "\"", 2, factorPositionPrimaryKeyColumns),
			)
			values := []interface{}{o.PositionID, rel.FactorPositionID}
			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.PositionID = o.PositionID
		}
	}
	if o.R == nil {
		o.R = &positionR{
			FactorPositions: related,
		}
	} else {
		o.R.FactorPositions = append(o.R.FactorPositions, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &factorPositionR{
				Position: o,
			}
		} else {
			rel.R.Position = o
		}
	}
	return nil
}
func ( o * Position ) AddFactorPositions ( ctx context . Context , exec boil . ContextExecutor , insert bool , related ... * FactorPosition ) error { var err error for _ , rel := range related { if insert { rel . PositionID = o . PositionID 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 , factorPositionPrimaryKeyColumns ) , ) values := [ ] interface { } { o . PositionID , rel . FactorPositionID } 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 . PositionID = o . PositionID } } if o . R == nil { o . R = & positionR { FactorPositions : related , } } else { o . R . FactorPositions = append ( o . R . FactorPositions , related ... ) } for _ , rel := range related { if rel . R == nil { rel . R = & factorPositionR { Position : o , } } else { rel . R . Position = o } } return nil }
AddFactorPositions adds the given related objects to the existing relationships
of the position, optionally inserting them as new records.
AddFactorPositions adds the given related objects to the existing relationships of the position optionally inserting them as new records .