123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805 |
- <!DOCTYPE HTML>
- <html lang="" >
- <head>
- <meta charset="UTF-8">
- <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
- <title>Change Log · GORM Guide</title>
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="description" content="">
- <meta name="generator" content="GitBook 3.2.3">
-
-
-
-
- <link rel="stylesheet" href="gitbook/style.css">
-
-
-
- <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
-
-
-
- <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
-
-
-
- <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <meta name="HandheldFriendly" content="true"/>
- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
- <meta name="apple-mobile-web-app-capable" content="yes">
- <meta name="apple-mobile-web-app-status-bar-style" content="black">
- <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
- <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
-
-
- <link rel="prev" href="development.html" />
-
- </head>
- <body>
-
- <div class="book">
- <div class="book-summary">
-
-
- <div id="book-search-input" role="search">
- <input type="text" placeholder="Type to search" />
- </div>
-
- <nav role="navigation">
-
- <div class="book-summary">
-
- <nav role="navigation">
- <ul class="summary">
-
-
-
- <li class="chapter " data-level="1.1" data-path="./">
-
- <a href="./">
-
-
- <b>1.1.</b>
-
- Getting Started with GORM
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.2" data-path="database.html">
-
- <a href="database.html">
-
-
- <b>1.2.</b>
-
- Database
-
- </a>
-
-
- <ul class="articles">
-
-
- <li class="chapter " data-level="1.2.1" data-path="database.html">
-
- <a href="database.html#connecting-to-a-database">
-
-
- <b>1.2.1.</b>
-
- Database Connection
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.2.2" data-path="database.html">
-
- <a href="database.html#migration">
-
-
- <b>1.2.2.</b>
-
- Migration
-
- </a>
-
-
- </li>
-
- </ul>
-
- </li>
-
- <li class="chapter " data-level="1.3" data-path="models.html">
-
- <a href="models.html">
-
-
- <b>1.3.</b>
-
- Models
-
- </a>
-
-
- <ul class="articles">
-
-
- <li class="chapter " data-level="1.3.1" data-path="models.html">
-
- <a href="models.html#model-definition">
-
-
- <b>1.3.1.</b>
-
- Model Definition
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3.2" data-path="models.html">
-
- <a href="models.html#conventions">
-
-
- <b>1.3.2.</b>
-
- Conventions & Overriding
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3.3" data-path="associations.html">
-
- <a href="associations.html">
-
-
- <b>1.3.3.</b>
-
- Associations
-
- </a>
-
-
- <ul class="articles">
-
-
- <li class="chapter " data-level="1.3.3.1" data-path="associations.html">
-
- <a href="associations.html#belongs-to">
-
-
- <b>1.3.3.1.</b>
-
- Belongs To
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3.3.2" data-path="associations.html">
-
- <a href="associations.html#has-one">
-
-
- <b>1.3.3.2.</b>
-
- Has One
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3.3.3" data-path="associations.html">
-
- <a href="associations.html#has-many">
-
-
- <b>1.3.3.3.</b>
-
- Has Many
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3.3.4" data-path="associations.html">
-
- <a href="associations.html#many-to-many">
-
-
- <b>1.3.3.4.</b>
-
- Many To Many
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3.3.5" data-path="associations.html">
-
- <a href="associations.html#polymorphism">
-
-
- <b>1.3.3.5.</b>
-
- Polymorphism
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.3.3.6" data-path="associations.html">
-
- <a href="associations.html#association-mode">
-
-
- <b>1.3.3.6.</b>
-
- Association Mode
-
- </a>
-
-
- </li>
-
- </ul>
-
- </li>
-
- <li class="chapter " data-level="1.3.4" data-path="dialects.html">
-
- <a href="dialects.html#dialect-data-type">
-
-
- <b>1.3.4.</b>
-
- Dialect Specific Data Type
-
- </a>
-
-
- </li>
-
- </ul>
-
- </li>
-
- <li class="chapter " data-level="1.4" data-path="crud.html">
-
- <a href="crud.html">
-
-
- <b>1.4.</b>
-
- CRUD: Reading and Writing Data
-
- </a>
-
-
- <ul class="articles">
-
-
- <li class="chapter " data-level="1.4.1" data-path="crud.html">
-
- <a href="crud.html#create">
-
-
- <b>1.4.1.</b>
-
- Create
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.4.2" data-path="crud.html">
-
- <a href="crud.html#query">
-
-
- <b>1.4.2.</b>
-
- Query
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.4.3" data-path="crud.html">
-
- <a href="crud.html#preloading-eager-loading">
-
-
- <b>1.4.3.</b>
-
- Preloading (Eager Loading)
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.4.4" data-path="crud.html">
-
- <a href="crud.html#update">
-
-
- <b>1.4.4.</b>
-
- Update
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.4.5" data-path="crud.html">
-
- <a href="crud.html#delete">
-
-
- <b>1.4.5.</b>
-
- Delete / Soft Delete
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.4.6" data-path="crud.html">
-
- <a href="crud.html#associations">
-
-
- <b>1.4.6.</b>
-
- Associations
-
- </a>
-
-
- </li>
-
- </ul>
-
- </li>
-
- <li class="chapter " data-level="1.5" data-path="callbacks.html">
-
- <a href="callbacks.html">
-
-
- <b>1.5.</b>
-
- Callbacks
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.6" data-path="advanced.html">
-
- <a href="advanced.html">
-
-
- <b>1.6.</b>
-
- Advanced Usage
-
- </a>
-
-
- <ul class="articles">
-
-
- <li class="chapter " data-level="1.6.1" data-path="advanced.html">
-
- <a href="advanced.html#error-handling">
-
-
- <b>1.6.1.</b>
-
- Error Handling
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.6.2" data-path="advanced.html">
-
- <a href="advanced.html#transactions">
-
-
- <b>1.6.2.</b>
-
- Transactions
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.6.3" data-path="advanced.html">
-
- <a href="advanced.html#sql-builder">
-
-
- <b>1.6.3.</b>
-
- Raw SQL & SQL Builder
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.6.4" data-path="advanced.html">
-
- <a href="advanced.html#generic-database-interface-sqldb">
-
-
- <b>1.6.4.</b>
-
- Generic database interface sql.DB
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.6.5" data-path="advanced.html">
-
- <a href="advanced.html#compose-primary-key">
-
-
- <b>1.6.5.</b>
-
- Composite Primary Key
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.6.6" data-path="advanced.html">
-
- <a href="advanced.html#logger">
-
-
- <b>1.6.6.</b>
-
- Overriding Logger
-
- </a>
-
-
- </li>
-
- </ul>
-
- </li>
-
- <li class="chapter " data-level="1.7" data-path="development.html">
-
- <a href="development.html">
-
-
- <b>1.7.</b>
-
- Development
-
- </a>
-
-
- <ul class="articles">
-
-
- <li class="chapter " data-level="1.7.1" data-path="development.html">
-
- <a href="development.html#architecture">
-
-
- <b>1.7.1.</b>
-
- Architecture
-
- </a>
-
-
- </li>
-
- <li class="chapter " data-level="1.7.2" data-path="development.html">
-
- <a href="development.html#write-plugins">
-
-
- <b>1.7.2.</b>
-
- Write Plugins
-
- </a>
-
-
- </li>
-
- </ul>
-
- </li>
-
- <li class="chapter active" data-level="1.8" data-path="changelog.html">
-
- <a href="changelog.html">
-
-
- <b>1.8.</b>
-
- Change Log
-
- </a>
-
-
- </li>
-
- <li class="divider"></li>
-
- </ul>
- </nav>
-
- </div>
- </nav>
-
-
- </div>
- <div class="book-body">
-
- <div class="body-inner">
-
-
- <div class="book-header" role="navigation">
-
- <!-- Title -->
- <h1>
- <i class="fa fa-circle-o-notch fa-spin"></i>
- <a href="." >Change Log</a>
- </h1>
- </div>
- <div class="page-wrapper" tabindex="-1" role="main">
- <div class="page-inner">
-
- <div id="book-search-results">
- <div class="search-noresults">
-
- <section class="normal markdown-section">
-
- <h1 id="change-log">Change Log</h1>
- <h2 id="v10">v1.0</h2>
- <h4 id="breaking-changes">Breaking Changes</h4>
- <ul>
- <li><p><strong><code>gorm.Open</code> return type <code>*gorm.DB</code> instead of <code>gorm.DB</code></strong></p>
- </li>
- <li><p><strong>Updating will only update changed fields</strong></p>
- <p>Most applications won't be affected, only when you are changing updating values in callbacks like <code>BeforeSave</code>, <code>BeforeUpdate</code>, you should use <code>scope.SetColumn</code> then, for example:</p>
- <pre><code class="lang-go"><span class="hljs-keyword">func</span> (user *User) BeforeUpdate(scope *gorm.Scope) {
- <span class="hljs-keyword">if</span> pw, err := bcrypt.GenerateFromPassword(user.Password, <span class="hljs-number">0</span>); err == <span class="hljs-literal">nil</span> {
- scope.SetColumn(<span class="hljs-string">"EncryptedPassword"</span>, pw)
- <span class="hljs-comment">// user.EncryptedPassword = pw // doesn't work, won't including EncryptedPassword field when updating</span>
- }
- }
- </code></pre>
- </li>
- <li><p><strong>Soft Delete's default querying scope will only check <code>deleted_at IS NULL</code></strong></p>
- <p>Before it will check <code>deleted_at</code> less than <code>0001-01-02</code> also to exclude blank time, like:</p>
- <p><code>SELECT * FROM users WHERE deleted_at IS NULL OR deleted_at <= '0001-01-02'</code></p>
- <p>But it is not necessary if you are using type <code>*time.Time</code> for your model's <code>DeletedAt</code>, which has been used by <code>gorm.Model</code>, so below SQl is enough</p>
- <p><code>SELECT * FROM users WHERE deleted_at IS NULL</code></p>
- <p>So if you are using <code>gorm.Model</code>, then you are good, nothing need to be change, just make sure all records having blank time for <code>deleted_at</code> set to <code>NULL</code>, sample migrate script:</p>
- </li>
- </ul>
- <pre><code class="lang-go"><span class="hljs-keyword">import</span> (
- <span class="hljs-string">"github.com/jinzhu/now"</span>
- )
- <span class="hljs-keyword">func</span> main() {
- <span class="hljs-keyword">var</span> models = []<span class="hljs-keyword">interface</span>{}{&User{}, &Image{}}
- <span class="hljs-keyword">for</span> _, model := <span class="hljs-keyword">range</span> models {
- db.Unscoped().Model(model).Where(<span class="hljs-string">"deleted_at < ?"</span>, now.MustParse(<span class="hljs-string">"0001-01-02"</span>)).Update(<span class="hljs-string">"deleted_at"</span>, gorm.Expr(<span class="hljs-string">"NULL"</span>))
- }
- }
- </code></pre>
- <ul>
- <li><p><strong>New ToDBName logic</strong></p>
- <p>Before when GORM convert Struct, Field's name to db name, only those common initialisms from <a href="https://github.com/golang/lint/blob/master/lint.go#L702" target="_blank">golint</a> like <code>HTTP</code>, <code>URI</code> are special handled.</p>
- <p>So field <code>HTTP</code>'s db name will be <code>http</code> not <code>h_t_t_p</code>, but some other initialisms like <code>SKU</code> that not in golint, it's db name will be <code>s_k_u</code>, which looks ugly, this release fixed this, any upper case initialisms should be converted correctly.</p>
- <p>If your applications using some upper case initialisms which doesn't exist in <a href="https://github.com/golang/lint/blob/master/lint.go#L702" target="_blank">golint</a>, you need to overwrite default column name with tag, like <code>gorm:"column:s_k_u"</code>, or alert your database's column name according to new logic</p>
- </li>
- <li><p>Error <code>RecordNotFound</code> has been renamed to <code>ErrRecordNotFound</code></p>
- </li>
- <li><p><code>mssql</code> driver has been moved out from default drivers, import it with <code>import _ "github.com/jinzhu/gorm/dialects/mssql"</code></p>
- </li>
- <li><p><code>Hstore</code> has been moved to package <code>github.com/jinzhu/gorm/dialects/postgres</code></p>
- </li>
- </ul>
-
- </section>
-
- </div>
- <div class="search-results">
- <div class="has-results">
-
- <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
- <ul class="search-results-list"></ul>
-
- </div>
- <div class="no-results">
-
- <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
-
- </div>
- </div>
- </div>
- </div>
- </div>
-
- </div>
-
-
- <a href="development.html#write-plugins" class="navigation navigation-prev navigation-unique" aria-label="Previous page: Write Plugins">
- <i class="fa fa-angle-left"></i>
- </a>
-
-
-
-
- </div>
- <script>
- var gitbook = gitbook || [];
- gitbook.push(function() {
- gitbook.page.hasChanged({"page":{"title":"Change Log","level":"1.8","depth":1,"previous":{"title":"Write Plugins","level":"1.7.2","depth":2,"anchor":"#write-plugins","path":"development.md","ref":"development.md#write-plugins","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"changelog.md","mtime":"2018-02-13T00:34:15.655Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-02-13T00:40:36.927Z"},"basePath":".","book":{"language":""}});
- });
- </script>
- </div>
-
- <script src="gitbook/gitbook.js"></script>
- <script src="gitbook/theme.js"></script>
-
-
- <script src="gitbook/gitbook-plugin-github/plugin.js"></script>
-
-
-
- <script src="gitbook/gitbook-plugin-edit-link/plugin.js"></script>
-
-
-
- <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
-
-
-
- <script src="gitbook/gitbook-plugin-search/search.js"></script>
-
-
-
- <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
-
-
-
- <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
-
-
-
- <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
-
-
-
- <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
-
-
- </body>
- </html>
|