// Save executes the query and returns the number of nodes affected by the update operation.
Save executes the query and returns the number of nodes affected by the update operation.
// Save executes the query and returns the number of nodes affected by the update operation .
func (su *ScopeUpdate) Save(ctx context.Context) (int, error) {
	var (
		err      error
		affected int
	)
	su.defaults()
	if len(su.hooks) == 0 {
		affected, err = su.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*ScopeMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			su.mutation = mutation
			affected, err = su.sqlSave(ctx)
			mutation.done = true
			return affected, err
		})
		for i := len(su.hooks) - 1; i >= 0; i-- {
			mut = su.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, su.mutation); err != nil {
			return 0, err
		}
	}
	return affected, err
}
func ( su * ScopeUpdate ) Save ( ctx context . Context ) ( int , error ) { var ( err error affected int ) su . defaults ( ) if len ( su . hooks ) == 0 { affected , err = su . sqlSave ( ctx ) } else { var mut Mutator = MutateFunc ( func ( ctx context . Context , m Mutation ) ( Value , error ) { mutation , ok := m . ( * ScopeMutation ) if ! ok { return nil , fmt . Errorf ( " " , m ) } su . mutation = mutation affected , err = su . sqlSave ( ctx ) mutation . done = true return affected , err } ) for i := len ( su . hooks ) - 1 ; i >= 0 ; i -- { mut = su . hooks [ i ] ( mut ) } if _ , err := mut . Mutate ( ctx , su . mutation ) ; err != nil { return 0 , err } } return affected , err }
Save executes the query and returns the number of nodes affected by the update operation.
Save executes the query and returns the number of nodes affected by the update operation .