title: How to prevent gorm from converting custom integer types into strings?
body: <p>I have troubles while using gorm with custom types that have integer properties. Gorm tends to convert the integer values into strings for me. There are two separate problems:</p>
  <p><strong>Problem 1:</strong></p>
  <p>I have a custom type defined as follows:</p>
  <pre><code>type ClientType uint8
  
  const (
      USER ClientType = iota
      SERVER
  )
  
  func (t ClientType) String() string {
      return [...]string{&quot;User&quot;, &quot;Service&quot;}[t]
  </code></pre>
  <p>And then I have a ORM struct for <code>Client</code> defined like this:</p>
  <pre><code>type Client struct {
      ClientID uint64 `gorm:&quot;primaryKey&quot;`
      UserID uint64
      ClientType ClientType
      CreatedAt time.Time
  }
  </code></pre>
  <p>When calling <code>db.Create(&amp;client)</code>, gorm automatically invokes the <code>String()</code> method on <code>ClientType</code>, and causes a data type mismatch in MySQL where I intend to store <code>ClientType</code> in a <code>TINYINT</code> column called <code>client_type</code>.</p>
  <p><strong>Problem 2:</strong></p>
  <p>So I thought if I can't figure out how to override the automatic calling of the <code>String()</code> method, I simply renamed the method to <code>ToString()</code> and call it when I need it. Now gorm can't invoke it any more, but instead, it casts the integer values into numeric strings instead. So <code>USER</code> which is <code>0</code>, will now become <code>'0'</code> in the resulting SQL statement, and <code>SERVER</code> will become <code>'1'</code>, although MySQL is able to cast the strings back to integers.</p>
  <p>I still wonder what I did wrong to make gorm think I wanted these conversions.</p>
  <ol>
  <li>Is there a way to override the calling of <code>String()</code>, so I can still name the method conventionally?</li>
  <li>Is it the use of <code>uint8</code> that made gorm converts the int to strings, since the other numeric values (ClientID and UserID) using uint64 were not affected by the issue? Is it some sort of caching of the DB schema that made gorm remember the old schema where client_type used to be an <code>ENUM('User', 'Service')</code> column?</li>
  </ol>