Update GORM guides

This commit is contained in:
Jinzhu 2016-08-16 16:59:30 +08:00
parent 902d0a479e
commit 7fcc575363
10 changed files with 17 additions and 11 deletions

View File

@ -70,7 +70,7 @@
data-chapter-title="Advanced Usage" data-chapter-title="Advanced Usage"
data-filepath="advanced.md" data-filepath="advanced.md"
data-basepath="." data-basepath="."
data-revision="Tue Aug 16 2016 16:37:38 GMT+0800 (CST)" data-revision="Tue Aug 16 2016 16:57:46 GMT+0800 (CST)"
data-innerlanguage=""> data-innerlanguage="">

View File

@ -70,7 +70,7 @@
data-chapter-title="Associations" data-chapter-title="Associations"
data-filepath="associations.md" data-filepath="associations.md"
data-basepath="." data-basepath="."
data-revision="Tue Aug 16 2016 16:37:38 GMT+0800 (CST)" data-revision="Tue Aug 16 2016 16:57:46 GMT+0800 (CST)"
data-innerlanguage=""> data-innerlanguage="">

View File

@ -70,7 +70,7 @@
data-chapter-title="Callbacks" data-chapter-title="Callbacks"
data-filepath="callbacks.md" data-filepath="callbacks.md"
data-basepath="." data-basepath="."
data-revision="Tue Aug 16 2016 16:37:38 GMT+0800 (CST)" data-revision="Tue Aug 16 2016 16:57:46 GMT+0800 (CST)"
data-innerlanguage=""> data-innerlanguage="">

View File

@ -68,7 +68,7 @@
data-chapter-title="Change Log" data-chapter-title="Change Log"
data-filepath="changelog.md" data-filepath="changelog.md"
data-basepath="." data-basepath="."
data-revision="Tue Aug 16 2016 16:37:38 GMT+0800 (CST)" data-revision="Tue Aug 16 2016 16:57:46 GMT+0800 (CST)"
data-innerlanguage=""> data-innerlanguage="">

View File

@ -70,7 +70,7 @@
data-chapter-title="CRUD: Reading and Writing Data" data-chapter-title="CRUD: Reading and Writing Data"
data-filepath="curd.md" data-filepath="curd.md"
data-basepath="." data-basepath="."
data-revision="Tue Aug 16 2016 16:37:38 GMT+0800 (CST)" data-revision="Tue Aug 16 2016 16:57:46 GMT+0800 (CST)"
data-innerlanguage=""> data-innerlanguage="">

View File

@ -70,7 +70,7 @@
data-chapter-title="Database" data-chapter-title="Database"
data-filepath="database.md" data-filepath="database.md"
data-basepath="." data-basepath="."
data-revision="Tue Aug 16 2016 16:37:38 GMT+0800 (CST)" data-revision="Tue Aug 16 2016 16:57:46 GMT+0800 (CST)"
data-innerlanguage=""> data-innerlanguage="">

View File

@ -70,7 +70,7 @@
data-chapter-title="Development" data-chapter-title="Development"
data-filepath="development.md" data-filepath="development.md"
data-basepath="." data-basepath="."
data-revision="Tue Aug 16 2016 16:37:38 GMT+0800 (CST)" data-revision="Tue Aug 16 2016 16:57:46 GMT+0800 (CST)"
data-innerlanguage=""> data-innerlanguage="">

View File

@ -68,7 +68,7 @@
data-chapter-title="Getting Started with GORM" data-chapter-title="Getting Started with GORM"
data-filepath="README.md" data-filepath="README.md"
data-basepath="." data-basepath="."
data-revision="Tue Aug 16 2016 16:37:38 GMT+0800 (CST)" data-revision="Tue Aug 16 2016 16:57:46 GMT+0800 (CST)"
data-innerlanguage=""> data-innerlanguage="">

View File

@ -70,7 +70,7 @@
data-chapter-title="Models" data-chapter-title="Models"
data-filepath="models.md" data-filepath="models.md"
data-basepath="." data-basepath="."
data-revision="Tue Aug 16 2016 16:37:38 GMT+0800 (CST)" data-revision="Tue Aug 16 2016 16:57:46 GMT+0800 (CST)"
data-innerlanguage=""> data-innerlanguage="">
@ -632,6 +632,7 @@
<li><a href="#conventions">Conventions</a><ul> <li><a href="#conventions">Conventions</a><ul>
<li><a href="#gormmodel-struct"><code>gorm.Model</code> struct</a></li> <li><a href="#gormmodel-struct"><code>gorm.Model</code> struct</a></li>
<li><a href="#table-name-is-the-pluralized-version-of-struct-name">Table name is the pluralized version of struct name</a></li> <li><a href="#table-name-is-the-pluralized-version-of-struct-name">Table name is the pluralized version of struct name</a></li>
<li><a href="#change-default-tablenames">Change default tablenames</a></li>
<li><a href="#column-name-is-the-snake-case-of-fields-name">Column name is the snake case of field&apos;s name</a></li> <li><a href="#column-name-is-the-snake-case-of-fields-name">Column name is the snake case of field&apos;s name</a></li>
<li><a href="#field-id-as-primary-key">Field <code>ID</code> as primary key</a></li> <li><a href="#field-id-as-primary-key">Field <code>ID</code> as primary key</a></li>
<li><a href="#field-createdat-used-to-store-records-created-time">Field <code>CreatedAt</code> used to store record&apos;s created time</a></li> <li><a href="#field-createdat-used-to-store-records-created-time">Field <code>CreatedAt</code> used to store record&apos;s created time</a></li>
@ -731,7 +732,12 @@
<span class="hljs-comment">// Disable table name&apos;s pluralization globally</span> <span class="hljs-comment">// Disable table name&apos;s pluralization globally</span>
db.SingularTable(<span class="hljs-literal">true</span>) <span class="hljs-comment">// if set this to true, `User`&apos;s default table name will be `user`, table name setted with `TableName` won&apos;t be affected</span> db.SingularTable(<span class="hljs-literal">true</span>) <span class="hljs-comment">// if set this to true, `User`&apos;s default table name will be `user`, table name setted with `TableName` won&apos;t be affected</span>
</code></pre> </code></pre>
<h3 id="column-name-is-the-snake-case-of-fields-name">Column name is the snake case of field&apos;s name</h3> <h3 id="change-default-tablenames">Change default tablenames</h3>
<p>You can apply any rules on the default table name by defining the <code>DefaultTableNameHandler</code></p>
<pre><code>gorm.DefaultTableNameHandler = func (db *gorm.DB, defaultTableName string) string {
return &quot;prefix_&quot; + defaultTableName;
}
</code></pre><h3 id="column-name-is-the-snake-case-of-fields-name">Column name is the snake case of field&apos;s name</h3>
<pre><code class="lang-go"><span class="hljs-keyword">type</span> User <span class="hljs-keyword">struct</span> { <pre><code class="lang-go"><span class="hljs-keyword">type</span> User <span class="hljs-keyword">struct</span> {
ID <span class="hljs-keyword">uint</span> <span class="hljs-comment">// column name will be `id`</span> ID <span class="hljs-keyword">uint</span> <span class="hljs-comment">// column name will be `id`</span>
Name <span class="hljs-keyword">string</span> <span class="hljs-comment">// column name will be `name`</span> Name <span class="hljs-keyword">string</span> <span class="hljs-comment">// column name will be `name`</span>

File diff suppressed because one or more lines are too long