go-gorm/gorm · error

unknown association operation type: %v

Error message

unknown association operation type: %v

What it means

Error "unknown association operation type: %v" thrown in go-gorm/gorm.

Source

Thrown at generics.go:755

		var r T
		return s.c.g.apply(ctx).Model(r).Create(data).Error
	}

	return nil
}

// executeAssociationOperation executes an association operation
func (s setCreateOrUpdateG[T]) executeAssociationOperation(ctx context.Context, op clause.Association) error {
	var r T
	base := s.c.g.apply(ctx).Model(r)

	switch op.Type {
	case clause.OpCreate:
		return s.handleAssociationCreate(ctx, base, op)
	case clause.OpUnlink, clause.OpDelete, clause.OpUpdate:
		return s.handleAssociation(ctx, base, op)
	default:
		return fmt.Errorf("unknown association operation type: %v", op.Type)
	}
}

func (s setCreateOrUpdateG[T]) handleAssociationCreate(ctx context.Context, base *DB, op clause.Association) error {
	if len(op.Set) > 0 {
		return s.handleAssociationForOwners(base, ctx, func(owner T, assoc *Association) error {
			data := make(map[string]interface{}, len(op.Set))
			for _, a := range op.Set {
				data[a.Column.Name] = a.Value
			}
			return assoc.Append(data)
		}, op.Association)
	}

	return s.handleAssociationForOwners(base, ctx, func(owner T, assoc *Association) error {
		return assoc.Append(op.Values...)
	}, op.Association)
}

View on GitHub (pinned to 1d6ce99528)

Solutions

  1. Use a supported association operation: Append, Replace, Delete, Clear, or Count.
  2. Check the value passed to the association mode call is one of the documented operation types.
  3. Upgrade GORM if the operation was introduced in a newer version.

Example fix

Use a supported association mode (Replace/Append/Delete/Clear) instead of an unknown operation type.

When it happens

Trigger: Thrown at generics.go:755 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of go-gorm/gorm@1d6ce99528 (2026-08-15). Data as JSON: /api/errors/31c0de8f30fe274c. Report an issue: GitHub.