func (o *Factor) AddFactorPositions(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*FactorPosition) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.FactorID = o.FactorID
			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{"factor_id"}),
				strmangle.WhereClause("\"", "\"", 2, factorPositionPrimaryKeyColumns),
			)
			values := []interface{}{o.FactorID, 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.FactorID = o.FactorID
		}
	}

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

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &factorPositionR{
				Factor: o,
			}
		} else {
			rel.R.Factor = o
		}
	}
	return nil
}
// AddFactorPositions adds the given related objects to the existing relationships
// of the factor, optionally inserting them as new records.
// Appends related to o.R.FactorPositions.
// Sets related.R.Factor appropriately.
AddFactorPositions adds the given related objects to the existing relationships
of the factor, optionally inserting them as new records.
Appends related to o.R.FactorPositions.
Sets related.R.Factor appropriately.
// AddFactorPositions adds the given related objects to the existing relationships // of the factor optionally inserting them as new records . // Appends related to o . R . FactorPositions . // Sets related . R . Factor appropriately .
func (o *Factor) AddFactorPositions(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*FactorPosition) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.FactorID = o.FactorID
			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{"factor_id"}),
				strmangle.WhereClause("\"", "\"", 2, factorPositionPrimaryKeyColumns),
			)
			values := []interface{}{o.FactorID, 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.FactorID = o.FactorID
		}
	}
	if o.R == nil {
		o.R = &factorR{
			FactorPositions: related,
		}
	} else {
		o.R.FactorPositions = append(o.R.FactorPositions, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &factorPositionR{
				Factor: o,
			}
		} else {
			rel.R.Factor = o
		}
	}
	return nil
}
func ( o * Factor ) AddFactorPositions ( ctx context . Context , exec boil . ContextExecutor , insert bool , related ... * FactorPosition ) error { var err error for _ , rel := range related { if insert { rel . FactorID = o . FactorID 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 . FactorID , 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 . FactorID = o . FactorID } } if o . R == nil { o . R = & factorR { FactorPositions : related , } } else { o . R . FactorPositions = append ( o . R . FactorPositions , related ... ) } for _ , rel := range related { if rel . R == nil { rel . R = & factorPositionR { Factor : o , } } else { rel . R . Factor = o } } return nil }
AddFactorPositions adds the given related objects to the existing relationships
of the factor, optionally inserting them as new records.
AddFactorPositions adds the given related objects to the existing relationships of the factor optionally inserting them as new records .