<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stanislas Michalak on Medium]]></title>
        <description><![CDATA[Stories by Stanislas Michalak on Medium]]></description>
        <link>https://medium.com/@stanislas_m?source=rss-7ac2946019f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GUAVtdPrM7iZ77HOuGlzYQ.jpeg</url>
            <title>Stories by Stanislas Michalak on Medium</title>
            <link>https://medium.com/@stanislas_m?source=rss-7ac2946019f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 15:42:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stanislas_m/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Associations with Pop: n to n]]></title>
            <link>https://medium.com/gobuffalo/associations-with-pop-n-to-n-4d315563a7a7?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d315563a7a7</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[association]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Mon, 17 Aug 2020 13:26:12 GMT</pubDate>
            <atom:updated>2026-09-29T13:00:00.485Z</atom:updated>
            <content:encoded><![CDATA[<p>Model relations with Pop are difficult to understand. Let’s fix that.</p><p>In this third article, you’ll learn <strong>how to properly write a many to many association and how to use it in a real context</strong>. But before going further, what’s a many to many association?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NwpvVqmhl1vRyLoG5gmKXw.jpeg" /><figcaption>Photo by Miguel Á. Padriñán from Pexels</figcaption></figure><h3>Definition</h3><p><strong>Note</strong>: If you want to refresh your memories about <strong>1 to 1</strong> and <strong>1 to n</strong> relations, here are the previous articles of this series:</p><ul><li><a href="https://blog.gobuffalo.io/associations-with-pop-1-to-1-592f02e2bdd8">Associations with Pop: 1 to 1</a></li><li><a href="https://blog.gobuffalo.io/associations-with-pop-1-to-n-2fb3e1c3833f">Associations with Pop: 1 to n</a></li></ul><p>In database theory, the objects we work on are called “entities”. These entities can have a different number of relations. Today, we’ll focus on the <strong>n to n</strong> (or many to many) association: this relation links many objects to many others.</p><p>Let’s design entities to represent students and their skills (Math, English and Biology, in our example). <strong>A student can have zero skills</strong> (that’s bad luck, though) <strong>or as many skills as he/she can</strong>: this means we can use a one to many relation here. <strong>Skills can be learned by many students</strong> (that means once a skill is learned, other students can still learn it). That’s also a one to many relation.</p><p>When you have one to many relations on both sides, they can be simplified as a <em>many to many relation</em>. It means:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*_IIYe6ivjOvFOsKACYA0yw.png" /></figure><p>is equivalent to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*ngXxkYRjbAxL_-9WBt5xHw.png" /></figure><p>To create such relation in the database, you’ll have to add another table between the tables for the entities. In many cases, this table will only contain two fields (one for each ID to store), but sometimes you’ll want to add more data.</p><h4>Carrying relations</h4><p>A carrying relation is a n to n relation which <strong>carries</strong> more data than just the two IDs. For instance, if I want I can add the date when the relation was created (in the student/skill example, it will be the date the student learned the skill).</p><p>This can be drawn like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*JCTi_0UmTT_h_fV9V0qnZQ.png" /></figure><h3>How to use it with pop</h3><blockquote><strong><em>Note</em></strong><em>: the following code can be found in a full example here: </em><a href="https://github.com/stanislas-m/pop-associations/tree/master/manytomany"><em>https://github.com/stanislas-m/pop-associations/tree/master/manytomany</em></a></blockquote><p>Pop uses meta tags on the models to define the relations. To define a many_to_many relation, you’ll need to use the many_to_many tag. But first, let’s create the tables in the database:</p><h4>Database migrations</h4><pre>create_table(&quot;students&quot;) {<br> t.Column(&quot;id&quot;, &quot;integer&quot;, {primary: true})<br> t.Column(&quot;name&quot;, &quot;string&quot;, {})<br> t.Timestamps()<br>}</pre><pre>create_table(&quot;skills&quot;) {<br> t.Column(&quot;id&quot;, &quot;integer&quot;, {primary: true})<br> t.Column(&quot;label&quot;, &quot;string&quot;, {})<br> t.Timestamps()<br>}</pre><pre>create_table(&quot;student_skills&quot;) {<br> t.Column(&quot;student_id&quot;, &quot;integer&quot;, {})<br> t.Column(&quot;skill_id&quot;, &quot;integer&quot;, {})<br> t.PrimaryKey(&quot;student_id&quot;, &quot;skill_id&quot;)<br>}</pre><p>Pretty classic way to define our tables, using the <a href="https://gobuffalo.io/docs/db/fizz/">fizz syntax</a>. The main addition here is the student_skills table to store our many to many relation.</p><p>I’ve defined a composite primary key (a primary key with more than one field) to make sure a student won’t try to learn a skill already known. You can also add foreign keys, but I’ll leave it as homework. :)</p><h4>many_to_many</h4><p>As we have our database tables now, we need to map them into our Go structs:</p><pre>type Skill struct {                   <br>    ID        int       `json:&quot;id&quot; db:&quot;id&quot;`<br>    Label     string    `json:&quot;label&quot; db:&quot;label&quot;`<br>    CreatedAt time.Time `json:&quot;created_at&quot; db:&quot;created_at&quot;`<br>    UpdatedAt time.Time `json:&quot;updated_at&quot; db:&quot;updated_at&quot;`                       }</pre><pre>type Student struct {<br>    ID        int       `json:&quot;id&quot; db:&quot;id&quot;`<br>    Name      string    `json:&quot;name&quot; db:&quot;name&quot;`<br>    CreatedAt time.Time `json:&quot;created_at&quot; db:&quot;created_at&quot;`<br>    UpdatedAt time.Time `json:&quot;updated_at&quot; db:&quot;updated_at&quot;`<br>    Skills    []Skill   `json:&quot;skills&quot; many_to_many:&quot;student_skills&quot; db:&quot;-&quot;`<br>}</pre><p>To declare the many to many relation, I used the many_to_many tag, which takes the name of the table defining the relation (here student_skills).</p><p>That’s it, we just need to write our queries, now!</p><h4>Query Usage</h4><p>Before fetching some data, we need to insert it into the database:</p><pre>skills := []models.Skill{<br>    {<br>        Label: &quot;Math&quot;,<br>    },<br>    {<br>        Label: &quot;English&quot;,<br>    },<br>    {<br>        Label: &quot;Biology&quot;,<br>    },<br>}<br>if err := c.Create(skills); err != nil {<br>    return err<br>}</pre><pre>// Create students with their skills<br>bob := &amp;models.Student{<br>    Name: &quot;Bob&quot;,<br>    Skills: []models.Skill{<br>        skills[1],<br>        skills[2],<br>    },<br>}<br>if err := c.Eager().Create(bob); err != nil {<br>    return err<br>}</pre><pre>alice := &amp;models.Student{<br>    Name: &quot;Alice&quot;,<br>    Skills: []models.Skill{<br>        skills[0],<br>        skills[2],<br>    },<br>}<br>if err := c.Eager().Create(alice); err != nil {<br>    return err<br>}</pre><p>In this piece of code, we created 3 “skills”: “Math”, “English” and “Biology”. Then, thanks to the Eager() method, we created Bob and Alice, two students with their skills.</p><p>Since we now have some students in the database, let’s list them:</p><pre>students := &amp;models.Students{}<br>if err := c.All(students); err != nil {<br>    log.Printf(&quot;err: %v&quot;, err)<br>    return<br>}<br>log.Printf(&quot;basic fetch: %v&quot;, students)</pre><p>As expected, without the <strong>Eager</strong> modifier, we gets the students without their skills:</p><pre>2020/08/17 15:20:04 basic fetch: [{&quot;id&quot;:1,&quot;name&quot;:&quot;Bob&quot;,&quot;created_at&quot;:&quot;2020-08-17T15:20:04.013204Z&quot;,&quot;updated_at&quot;:&quot;2020-08-17T15:20:04.013209Z&quot;,&quot;skills&quot;:null},{&quot;id&quot;:2,&quot;name&quot;:&quot;Alice&quot;,&quot;created_at&quot;:&quot;2020-08-17T15:20:04.018426Z&quot;,&quot;updated_at&quot;:&quot;2020-08-17T15:20:04.01843Z&quot;,&quot;skills&quot;:null}]</pre><p>Let’s try with the <strong>Eager</strong> modifier now:</p><pre>students = &amp;models.Students{}<br>if err := c.Eager().All(students); err != nil {<br>    log.Printf(&quot;err: %v&quot;, err)<br>    return<br>}<br>log.Printf(&quot;eager fetch: %v&quot;, students)</pre><p>Here’s the result:</p><pre>2020/08/17 15:20:04 eager fetch: [{&quot;id&quot;:1,&quot;name&quot;:&quot;Bob&quot;,&quot;created_at&quot;:&quot;2020-08-17T15:20:04.013204Z&quot;,&quot;updated_at&quot;:&quot;2020-08-17T15:20:04.013209Z&quot;,&quot;skills&quot;:[{&quot;id&quot;:2,&quot;label&quot;:&quot;English&quot;,&quot;created_at&quot;:&quot;2020-08-17T15:20:04.009054Z&quot;,&quot;updated_at&quot;:&quot;2020-08-17T15:20:04.009062Z&quot;},{&quot;id&quot;:3,&quot;label&quot;:&quot;Biology&quot;,&quot;created_at&quot;:&quot;2020-08-17T15:20:04.01108Z&quot;,&quot;updated_at&quot;:&quot;2020-08-17T15:20:04.011086Z&quot;}]},{&quot;id&quot;:2,&quot;name&quot;:&quot;Alice&quot;,&quot;created_at&quot;:&quot;2020-08-17T15:20:04.018426Z&quot;,&quot;updated_at&quot;:&quot;2020-08-17T15:20:04.01843Z&quot;,&quot;skills&quot;:[{&quot;id&quot;:1,&quot;label&quot;:&quot;Math&quot;,&quot;created_at&quot;:&quot;2020-08-17T15:20:04.000139Z&quot;,&quot;updated_at&quot;:&quot;2020-08-17T15:20:04.000146Z&quot;},{&quot;id&quot;:3,&quot;label&quot;:&quot;Biology&quot;,&quot;created_at&quot;:&quot;2020-08-17T15:20:04.01108Z&quot;,&quot;updated_at&quot;:&quot;2020-08-17T15:20:04.011086Z&quot;}]}]</pre><p>This is the end of this third article about the n to n associations with Pop. I hope you enjoyed this series, even if I took so much time to release each article!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e7Jgc-mq90XLjVPgPRaipQ.png" /></figure><p>These days I’m filling my spare time working on <strong>NuCorder</strong>, a platform to play with other musicians remotely from your home:</p><p><a href="https://www.nucorder.fr/">NuCorder - Play with your band on remote</a></p><p>If you’re interested, please take a look and ask for missing features on <a href="https://www.nucorder.fr/contact">https://www.nucorder.fr/contact</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d315563a7a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/associations-with-pop-n-to-n-4d315563a7a7">Associations with Pop: n to n</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Associations with Pop: 1 to n]]></title>
            <link>https://medium.com/gobuffalo/associations-with-pop-1-to-n-2fb3e1c3833f?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fb3e1c3833f</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[association]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Tue, 11 Jun 2019 18:27:38 GMT</pubDate>
            <atom:updated>2020-08-11T06:34:23.772Z</atom:updated>
            <content:encoded><![CDATA[<p>Model relations with Pop are difficult to understand. Let’s fix that.</p><p>In this second article, you’ll learn <strong>how to properly write a one to many association and how to use it in a real context</strong>. But before going further, what’s a one to many association?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MQLhwQ6N9wJd6nahCaU94w.jpeg" /><figcaption>Photo by Miguel Á. Padriñán from Pexels</figcaption></figure><h3>Definition</h3><blockquote><strong>Note</strong>: If you want to learn more about 1 to 1 associations before heading to 1 to n ones, you can find the first article of this series here:</blockquote><p><a href="https://blog.gobuffalo.io/associations-with-pop-1-to-1-592f02e2bdd8">Associations with Pop: 1 to 1</a></p><p>In database theory, we’re used to name “entities” the objects we work on. These entities can have a different number of relations. Today, we’ll focus on the <strong>1 to n</strong> (or 1 to many) association: this relation links one object to many others.</p><p>For instance, the relation between a fruit and a tree is a 1 to n relation: “<strong>a fruit is attached to one and only one tree</strong>”, but “<strong>a tree can produce 0, 1 or as many fruits </strong>as it can”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*H_i8-btWX_taTxMWGug8gw.png" /><figcaption>A standard notation of the previous example.</figcaption></figure><p>The “1” on the drawing is the same as the “1” in the 1 to 1 relation. It means you can only have a single relation in this side, and this relation is mandatory (a fruit can’t just appear without growing on a tree! — or maybe, if you try with some bananas and a microwave).</p><p>The “0..n” notation is new here: it describes a range, saying you can have 0 to as many objects as you want (that’s what “n” means). If I replace the “0” with a “1” (so “1..n”), it’ll mean you can’t have a tree if it doesn’t have a fruit on it (“1” have a mandatory value, here).</p><p>“1” can also be written “1..1”, but why would you want to write something longer?</p><h3>How to use it with pop</h3><blockquote><strong>Note</strong>: the following code can be found in a full example here: <a href="https://github.com/stanislas-m/pop-associations/tree/master/onetomany">https://github.com/stanislas-m/pop-associations/tree/master/onetomany</a></blockquote><p>Pop deals with relations using meta tags you can attach on your model structs: “<strong>has_many</strong>” and “<strong>belongs_to</strong>”. Before using them, we have to create the matching tables in the database:</p><h4>Database migrations</h4><p>First, let’s define our tree and fruit as tables, using fizz migrations:</p><pre>create_table(&quot;trees&quot;) {<br> t.Column(&quot;id&quot;, &quot;integer&quot;, {&quot;primary&quot;: true})<br> t.Column(&quot;name&quot;, &quot;string&quot;, {})<br> t.DisableTimestamps()<br>}<br>create_table(&quot;fruits&quot;) {<br> t.Column(&quot;id&quot;, &quot;integer&quot;, {&quot;primary&quot;: true})<br> t.Column(&quot;tree_id&quot;, &quot;integer&quot;, {})<br> t.ForeignKey(&quot;tree_id&quot;, {&quot;trees&quot;: [&quot;id&quot;]}, {})<br> t.DisableTimestamps()<br>}</pre><p>So a tree has an id (it’s primary key) and a name (“Apple tree”, for instance). A fruit has its own id, and a reference to a tree id which we enforce using a foreign key.</p><p>For both tables, I disabled the auto-timestamp feature because I don’t need it here.</p><h4>has_many</h4><p>Now that your tables are properly created in the database, we can map them to proper entities:</p><pre>type Fruit struct {<br>    ID     int   `json:&quot;id,omitempty&quot; db:&quot;id&quot;`<br>    TreeID int   `json:&quot;-&quot; db:&quot;tree_id&quot;`<br>    Tree   *Tree `json:&quot;tree,omitempty&quot; belongs_to:&quot;tree&quot;`                       }</pre><pre>type Tree struct {<br>    ID     int     `json:&quot;id&quot; db:&quot;id&quot;`<br>    Name   string  `json:&quot;name&quot; db:&quot;name&quot;`<br>    Fruits []Fruit `json:&quot;fruits,omitempty&quot; has_many:&quot;fruits&quot;`                       }</pre><p>A one to many relationship is a relation between a single entity and a collection (or slice, in Go) of entities. We then need to use different struct tags to define both sides of the relationship. Here’s how it works:</p><ul><li>The side with the single entity (the Fruit) uses the <em>belongs_to</em> tag. It’s the same we used for the one to one relation (see <a href="https://blog.gobuffalo.io/associations-with-pop-1-to-1-592f02e2bdd8">https://blog.gobuffalo.io/associations-with-pop-1-to-1-592f02e2bdd8</a>). We’ll store a reference to the related model here (the <em>tree_id</em> in our case).</li><li>The side with the slice (the Tree) uses the <em>has_many</em> tag.</li></ul><p>This <em>has_many</em> tag is more or less a plural version of <em>has_one</em>: it defines the following side, i.e. the one letting the owning side do the relationship work.</p><p>In our example, the following side will be the <strong>tree</strong>, since the table doesn’t contain an extra field for the relation. As a reminder, you can say “the tree <em>has many</em> fruits”.</p><p>That’s it! You can now use the relation in a query. :)</p><h4>Query Usage</h4><p>Before fetching some data, we need to insert it into the database:</p><pre>// Create some fruits<br>fruits := make([]models.Fruit, 5)<br>for i:= 0; i &lt; 5; i++ {<br>    fruits[i] = models.Fruit{}<br>}<br>b := &amp;models.Tree{<br>    Name:   &quot;Tree&quot;,<br>    Fruits: fruits,<br>}</pre><pre>if err := c.Eager().Create(b); err != nil {<br>    return err<br>}</pre><p>In this piece of code, we created 5 fruits, then a tree and we attached the 5 fruits to the tree. Thanks to the Eager() modifier, the Create() method saved the whole tree with its fruits in the database!</p><p>Now we have some data in the database, let’s try to fetch some trees:</p><pre>trees := &amp;models.Trees{}</pre><pre>if err := c.All(trees); err != nil {<br>    log.Printf(&quot;err: %v&quot;, err)<br>    return<br>}</pre><pre>log.Printf(&quot;basic fetch: %v&quot;, trees)</pre><p>Here’s an example with 3 trees:</p><pre>2019/06/11 20:18:18 basic fetch trees: [{&quot;id&quot;:1,&quot;name&quot;:&quot;Tree 0&quot;},{&quot;id&quot;:2,&quot;name&quot;:&quot;Tree 1&quot;},{&quot;id&quot;:3,&quot;name&quot;:&quot;Tree 2&quot;}]</pre><p>As you can see, the trees were fetch without the apples. To fetch the trees with their apples, we need to use the Eager() modifier:</p><pre>trees = &amp;models.Trees{}</pre><pre>if err := c.Eager().All(trees); err != nil {<br>    log.Printf(&quot;err: %v&quot;, err)<br>    return<br>}</pre><pre>log.Printf(&quot;eager fetch: %v&quot;, trees)</pre><p>And here is the new result:</p><pre>2019/06/11 20:18:18 eager fetch trees: [{&quot;id&quot;:1,&quot;name&quot;:&quot;Tree 0&quot;},{&quot;id&quot;:2,&quot;name&quot;:&quot;Tree 1&quot;,&quot;fruits&quot;:[{&quot;id&quot;:1}]},{&quot;id&quot;:3,&quot;name&quot;:&quot;Tree 2&quot;,&quot;fruits&quot;:[{&quot;id&quot;:2},{&quot;id&quot;:3}]}]</pre><p>This is the end of this second article about the 1 to n associations with Pop. The next article will cover the last kind of association: <strong>n to n</strong> (or many to many).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fb3e1c3833f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/associations-with-pop-1-to-n-2fb3e1c3833f">Associations with Pop: 1 to n</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pop v4.11.0 Released!]]></title>
            <link>https://medium.com/gobuffalo/pop-v4-11-0-released-6a727127d7d9?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a727127d7d9</guid>
            <category><![CDATA[gobuffalo]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[orm]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Tue, 07 May 2019 09:51:18 GMT</pubDate>
            <atom:updated>2020-08-11T06:35:01.687Z</atom:updated>
            <content:encoded><![CDATA[<p>This is mostly a maintenance release, so no funky new feature for this version. :)</p><p>In addition to what is listed here, I recommend you read the <a href="https://github.com/gobuffalo/pop/releases/tag/v4.10.0">CHANGELOG</a> for a complete list of what has changed in v4.11.0.</p><h3>How to Upgrade</h3><h4>Standalone</h4><p>First, if you use soda without the Buffalo integration, you can upgrade the binary from source, using go get:</p><pre>$ go get -u -v github.com/gobuffalo/pop/soda</pre><p>You can also download a pre-built binary at:<br><a href="https://github.com/gobuffalo/pop/releases/tag/v4.11.0">https://github.com/gobuffalo/pop/releases/tag/v4.11.0</a></p><h4>Buffalo version</h4><p>If you use the Buffalo integration, you’ll have to upgrade the buffalo-pop plugin to use this version:</p><pre>$ go get -u -v github.com/gobuffalo/buffalo-pop</pre><p>For both versions, if you are using dep, and you pinned Pop to a specific version, you should change the version in Gopkg.toml to v4.11.0. Then run dep ensure -update to update your dependencies.</p><p>Otherwise, just run dep ensure -update to update your dependencies.</p><h4>Go Modules (beta)</h4><p>You can use Pop with Go modules:</p><p>go.mod:</p><pre>module github.com/gobuffalo/pop-test</pre><pre>require (<br>    github.com/gobuffalo/pop v4.11.0<br>)</pre><h3>What’s New</h3><h4>Timestamps() macro by default</h4><p>Currently Fizz is enforcing an old Pop rule that timestamps columns are added implicitly. In an effort to make Fizz usable outside Pop world (let’s say with GORM, for instance), we’ll change this behavior in a close-future Fizz version: <strong>timestamp columns (</strong><strong>created_at and </strong><strong>updated_at) will not be be created automatically anymore </strong>by Fizz.</p><p>While this is useful for Fizz, this will break Pop behavior. To solve this problem, Pop will now add the t.Timestamps() macro to new generated migrations, which will generate these columns explicitly.</p><p>You are encouraged to patch your current migrations to add this statement if you currently rely on this auto feature, so your patches will not break when we’ll make this change in Fizz.</p><blockquote><strong>Hot tip</strong>: The soda fix command was also updated to take care of this issue: run it and it will try to update your patches to the latest format.</blockquote><h4>Legacy Anko format auto fixer removed</h4><p>A long time ago, we migrated our Fizz interpreter engine from <a href="https://github.com/mattn/anko">Anko templates</a> (which was regularly broken) to <a href="https://github.com/gobuffalo/plush">Plush templates</a>. To make the migration to the new format as smooth as possible, we created a patch tool which fixes the old migrations to use the new format.</p><p>Pop used to try to convert old patches before applying them, so users of old versions still had time to migrate to the new format.</p><p>This patch tool is still used in the soda fix command, but we disabled the hot-patching on runtime.</p><h4>“has_one” pointer association fixed</h4><p><em>has_one</em> associations didn’t work with pointers. Now it works fine. :)</p><h4>IdlePool option fixed</h4><p>IdlePool Pop option allows you to manage the <a href="https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns">SetMaxIdleConns</a> parameter on your connection, so you can control the number of idle connections you want to keep with your database.</p><p>The zero value was not the same as in the standard library and could cause<br> performances issues. Pop won’t call SetMaxIdleConns now when IdlePool<br> is set to the zero value, so it will default to the standard library default one.</p><p>I hope you’ll enjoy this new version! Feel free to<a href="https://github.com/gobuffalo/pop/issues"> open an issue</a> if you find a bug, or ask for support on the <a href="https://gobuffalo.io/en/docs/slack">buffalo Slack channel</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a727127d7d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/pop-v4-11-0-released-6a727127d7d9">Pop v4.11.0 Released!</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pop v4.10.0 Released!]]></title>
            <link>https://medium.com/gobuffalo/pop-v4-10-0-released-4ef66b20320f?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ef66b20320f</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[gobuffalo]]></category>
            <category><![CDATA[orm]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Mon, 11 Mar 2019 13:54:33 GMT</pubDate>
            <atom:updated>2020-08-11T06:35:41.947Z</atom:updated>
            <content:encoded><![CDATA[<p>Custom model path, migration to gofrs/uuid and more. Discover the new Pop release!</p><p>In addition to what is listed here, I recommend you read the <a href="https://github.com/gobuffalo/pop/releases/tag/v4.10.0">CHANGELOG</a> for a complete list of what has changed in v4.10.0.</p><h3>How to Upgrade</h3><h4>Standalone</h4><p>First, if you use soda without the Buffalo integration, you can upgrade the binary from source, using go get:</p><pre>$ go get -u -v github.com/gobuffalo/pop/soda</pre><p>You can also download a pre-built binary at:<br><a href="https://github.com/gobuffalo/pop/releases/tag/v4.10.0">https://github.com/gobuffalo/pop/releases/tag/v4.10.0</a></p><h4>Buffalo version</h4><p>If you use the Buffalo integration, you’ll have to upgrade the buffalo-pop plugin to use this version:</p><pre>$ go get -u -v github.com/gobuffalo/buffalo-pop</pre><p>For both versions, if you are using dep, and you pinned Pop to a specific version, you should change the version in Gopkg.toml to v4.10.0. Then run dep ensure -update to update your dependencies.</p><p>Otherwise, just run dep ensure -update to update your dependencies.</p><h4>Go Modules (beta)</h4><p>You can use Pop with Go modules:</p><p>go.mod:</p><pre>module github.com/gobuffalo/pop-test</pre><pre>require (<br>    github.com/gobuffalo/pop v4.10.0<br>)</pre><h3>What’s New</h3><h4>Custom model path</h4><p>There’s a new --models-path option to soda generate model that allows changing where the model will be created. The package name will be the last folder in the path.</p><p>For example:</p><pre>soda generate model User --models-path models/admin</pre><p>…would create the model files in ./models/admin, and make them part of the admin package.</p><h4>Migration to gofrs/uuid</h4><p>Since we forked the <a href="https://github.com/satori/go.uuid">https://github.com/satori/go.uuid</a> repository, we didn’t take time to manage the project and fix some bugs. Meanwhile, the <a href="https://github.com/gofrs/uuid">https://github.com/gofrs/uuid</a> fork was created outside the Buffalo org, and the folks managing it are pretty active. We then decided to migrate our code base and our users to the gofrs/uuid fork!</p><p>The first step to allow the transition was to forward our fork types and functions to the gofrs ones, so it will be smoother for our users to migrate to gofrs fork later. We did it a few months ago, and no particular issue was reported.</p><p>In this release, we made the last step by changing our references in Pop from gobuffalo/uuid to gofrs/uuid. If you’re currently using UUID types, you should consider migrating your imports to the gofrs/uuid ones, as we won’t maintain the gobuffalo/uuid repo anymore.</p><p>New code generated by soda will reflect this change by generating gofrs/uuid imports instead of gobuffalo/uuid ones.</p><h4>Migration to gobuffalo/nulls</h4><p>In an effort to make the Buffalo ecosystem more modulable, and allow people to take only the parts they want from it, we extracted the pop/nulls package from the pop repo to its own repo. This way, you’ll be able to use pop nulls even without pop.</p><p>New generated code will apply this change, and old code should still work (and pop/nulls are redirected to gobuffalo/nulls now).</p><h4>buffalo-pop plugin with SQLite support</h4><p>Using buffalo-pop, the Buffalo plugin for pop, should be easy and you shouldn’t need to install it from source if you want SQLite support.</p><p>As we already provide soda pre-compiled binaries with SQLite support, buffalo-pop plugin now follow the same path: you can now just download the pre-compiled plugin with SQLite support from either GitHub releases page or using homebrew.</p><p>I hope you’ll enjoy this new version! Feel free to<a href="https://github.com/gobuffalo/pop/issues"> open an issue</a> if you find a bug, or ask for support on the <a href="https://gobuffalo.io/en/docs/slack">buffalo Slack channel</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ef66b20320f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/pop-v4-10-0-released-4ef66b20320f">Pop v4.10.0 Released!</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Associations with Pop: 1 to 1]]></title>
            <link>https://medium.com/gobuffalo/associations-with-pop-1-to-1-592f02e2bdd8?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/592f02e2bdd8</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[association]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Tue, 13 Nov 2018 13:01:01 GMT</pubDate>
            <atom:updated>2020-08-11T06:35:58.004Z</atom:updated>
            <content:encoded><![CDATA[<p>Model relations with Pop are difficult to understand. Let’s fix that.</p><p>In this first article, you’ll learn <strong>how to properly write a one to one association and how to use it in a real context</strong>. But first thing first, what’s a one to one association?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XF1PQcOSYwG3541wsNT4Vg.jpeg" /><figcaption>Photo by Miguel Á. Padriñán from Pexels</figcaption></figure><h3>Definition</h3><p>In relational database theory, an object is <em>an entity</em>. This entity can be attached, linked to others entities. They can be of the same kind, but it’s not required.</p><p>Given the use case, your object can have zero, one, or as many relations as it needs. Today we’ll focus on the case where you have a <strong>one to one relation</strong>: this relation associates one object to another, and you can’t have more than one associated object.</p><p>For instance, the relation between the human body and its head is a one to one relation: you can confirm that by saying (in your head, please don’t disturb your neighbor) “<strong>the human body has one and only one head</strong>” and conversely “<strong>a human head is attached to one and only one body</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/195/1*S0mHnMCrTLF7oRPa7ShYGA.png" /><figcaption>A human head and its relation to the human body.</figcaption></figure><p>Instead of drawing real things, people working on that kind of stuff prefer to use a convention. They name the objects they work on and use that arrow notation I used in the previous drawing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*gwmHopESbM6MUp626_a60g.png" /><figcaption>A standard notation version of the previous drawing.</figcaption></figure><p>In this notation, objects are potato-shapes and the relation between the objects is materialized with an arrow. The numbers on the arrow give what we call the <a href="https://en.wikipedia.org/wiki/Cardinality"><em>cardinality</em></a>: that’s the number of relations the objects can have together. In this case, the number “1” on both sides means for each head we have, we must have one and only one body (and conversely).</p><h3>How to use it with pop</h3><blockquote><strong>Note</strong>: the following code can be found in a full example here: <a href="https://github.com/stanislas-m/pop-associations/tree/master/onetoone">https://github.com/stanislas-m/pop-associations/tree/master/onetoone</a></blockquote><p>Pop deals with relations using meta tags you can attach on your model structs: “<strong>has_one</strong>” and “<strong>belongs_to</strong>”.</p><p>Why using a different tag for the same thing? Well, that’s because databases use tables to represent data; and to represent a relation, we’ll need to store an ID pointing to the referenced entity. Databases don’t like to handle duplicated information, so we’ll have to choose on which side we’ll store this data: this side is called the <em>owning side</em> and the other the <em>following (</em>or<em> inverse) side</em>.</p><h4>Database migrations</h4><p>Let’s define our body and head as tables, using fizz migrations:</p><pre>create_table(&quot;bodies&quot;) {<br> t.Column(&quot;id&quot;, &quot;integer&quot;, {&quot;primary&quot;: true})<br>}</pre><pre>create_table(&quot;heads&quot;) {<br> t.Column(&quot;id&quot;, &quot;integer&quot;, {&quot;primary&quot;: true})<br> t.Column(&quot;body_id&quot;, &quot;integer&quot;, {})<br> t.ForeignKey(&quot;body_id&quot;, {&quot;bodies&quot;: [&quot;id&quot;]}, {})<br>}</pre><p><strong>Pop follows conventions</strong>, which tell that the <strong>table names are the plural </strong><a href="https://en.wikipedia.org/wiki/Snake_case"><strong>snake-cased</strong></a><strong> form</strong> of the Go struct name: “bodies” is the table for the “Body” struct, and “heads” the table for the “Head” struct.</p><p>So this migration will create a “bodies” table with an “id” integer field; and a “heads” table with an “id” integer field and a “body_id” field to store the association. It will also create a foreign key on “body_id” to ensure the relation integrity. This foreign key isn’t required by Pop, but, you know, people working on relational databases like to keep their data integrity safe.</p><p>Let’s go back to the Go code:</p><h4>belongs_to</h4><p>“belongs_to” tag is used to define the owning side. It’ll drive the relation by storing an extra field in its table.</p><p>In our example, the owning side will be the <strong>head</strong>: that’s the table containing the extra field for the relation, if you take a look back to the fizz migrations.</p><p>Here is how you’ll define it as a struct:</p><pre>type Head struct {<br>  ID           int<br>  BodyID       int        `db:&quot;body_id&quot;`<br>  Body         *Body       `belongs_to:&quot;body&quot;`<br>}</pre><p>The <em>Body</em> attribute is a pointer type because otherwise <strong>it would make a cycle</strong> between <em>Body</em> and <em>Head</em> Go structs. <strong>Such code is not allowed to compile</strong>, so we either need to drop the Head attribute on the Body struct or declare <em>Body</em> in the <em>Head</em> struct as a pointer.</p><blockquote><strong>Note: make sure to not forget the <em>BodyID</em> attribute</strong>: it’s used by Pop to hold the ID value to fetch the association and <strong>it’s mandatory</strong>!</blockquote><h4>has_one</h4><p>“has_one” is used to define the following side. There’s no need to store extra information, because the owning side will take care of it.</p><p>In our example, the following side will be the <strong>body</strong>, since the table doesn’t contain an extra field for the relation. As a reminder, you can say “the body <em>has one</em> head”.</p><p>Here’s how you’ll define it as a struct:</p><pre>type Body struct {<br>  ID           int<br>  Head         Head       `has_one:&quot;head&quot;`<br>}</pre><p>We don’t have a holder struct field for an foreign ID here: that’s the role of the belongs_to on the other side.</p><blockquote><strong>Note</strong>: this side of the relation is not mandatory at all. You can remove the Head attribute if you prefer to use the relation on the owner side only.</blockquote><p>Now, we’re ready to use the relation in a query!</p><h4>Query Usage</h4><p>If we want to fetch some data, we need to create the said data first:</p><pre>b := &amp;models.Body{<br>    Head: models.Head{},<br>}</pre><pre>if err := c.Eager().Create(b); err != nil {<br>    return err<br>}</pre><p>This piece of code declares a Body containing a Head, then it <em>Eager</em> creates the whole struct. The key part here is the Eager() modifier we applied before the Create method.</p><p>Try the same code without <em>Eager</em>, and the Head won’t be created in the database.</p><p>Next, we want to fetch the new Body from the database:</p><pre>bodies := &amp;models.Bodies{}</pre><pre>if err := c.All(bodies); err != nil {<br>    log.Printf(&quot;err: %v&quot;, err)<br>    return<br>}</pre><pre>log.Printf(&quot;basic fetch: %v&quot;, bodies)</pre><p>If you try this code, the bodies will be fetched from the database, but without the associated heads (head is the empty object {}). Here is an example with 3 bodies:</p><pre>2018/11/12 23:37:55 basic fetch: [{&quot;id&quot;:10,&quot;head&quot;:{}},{&quot;id&quot;:11,&quot;head&quot;:{}},{&quot;id&quot;:12,&quot;head&quot;:{}}]</pre><p>To fetch the whole struct, we’ll need… Eager() that’s it!</p><pre>bodies = &amp;models.Bodies{}</pre><pre>if err := c.Eager().All(bodies); err != nil {<br>    log.Printf(&quot;err: %v&quot;, err)<br>    return<br>}</pre><pre>log.Printf(&quot;eager fetch: %v&quot;, bodies)</pre><p>Here is the new result:</p><pre>2018/11/12 23:37:55 eager fetch: [{&quot;id&quot;:10,&quot;head&quot;:{&quot;id&quot;:10}},{&quot;id&quot;:11,&quot;head&quot;:{&quot;id&quot;:11}},{&quot;id&quot;:12,&quot;head&quot;:{&quot;id&quot;:12}}]</pre><p>This is the end of this first article about the 1 to 1 associations with Pop. The next article will cover another kind of association: <strong>1 to n</strong> (or 1 to many).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=592f02e2bdd8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/associations-with-pop-1-to-1-592f02e2bdd8">Associations with Pop: 1 to 1</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pop v4.9.0 Released!]]></title>
            <link>https://medium.com/gobuffalo/pop-v4-9-0-released-77eeb63ff66?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/77eeb63ff66</guid>
            <category><![CDATA[gobuffalo]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[orm]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Sat, 10 Nov 2018 14:29:35 GMT</pubDate>
            <atom:updated>2020-08-11T06:36:21.319Z</atom:updated>
            <content:encoded><![CDATA[<p>Eager creation, better CockroachDB support and more. Discover the new Pop release!</p><p>In addition to what is listed here, I recommend you read the <a href="https://github.com/gobuffalo/pop/releases/tag/v4.9.0">CHANGELOG</a> for a complete list of what has changed in v4.9.0.</p><h3>How to Upgrade</h3><h4>Standalone</h4><p>First, if you use soda without the Buffalo integration, you can upgrade the binary from source, using go get:</p><pre>$ go get -u -v github.com/gobuffalo/pop/soda</pre><p>You can also download a pre-built binary at:<br><a href="https://github.com/gobuffalo/pop/releases/tag/v4.9.0">https://github.com/gobuffalo/pop/releases/tag/v4.9.0</a></p><h4>Buffalo version</h4><p>If you use the Buffalo integration, you’ll have to upgrade the buffalo-pop plugin to use this version:</p><pre>$ go get -u -v github.com/gobuffalo/buffalo-pop</pre><p>For both versions, if you are using dep, and you pinned Pop to a specific version, you should change the version in Gopkg.toml to v4.9.0. Then run dep ensure -update to update your dependencies.</p><p>Otherwise, just run dep ensure -update to update your dependencies.</p><h4>Go Modules (beta)</h4><p>You can use Pop with Go modules:</p><p>go.mod:</p><pre>module github.com/gobuffalo/pop-test</pre><pre>require (<br>    github.com/gobuffalo/pop v4.9.0<br>)</pre><h3>What’s New</h3><h4>Eager Creation</h4><p>Pop already have support for Eager loading, which allows to manage relations with other structs.</p><p>In this version, we introduce official support for Eager creation! It covers cases when you want to save embedded structs and the root struct in one single shot:</p><pre>user := User{<br>    Name: &quot;Mark Bates&quot;,<br>    Books: Books{{Title: &quot;Pop Book&quot;, Description: &quot;Pop Book&quot;, Isbn: &quot;PB1&quot;}},<br>    FavoriteSong: Song{Title: &quot;Don&#39;t know the title&quot;},<br>    Houses: Addresses{<br>        Address{HouseNumber: 1, Street: &quot;Golang&quot;},<br>    },<br>}</pre><pre>err := tx.Eager().Create(&amp;user)</pre><p>If you prefer to manage the things by yourself, you still can use the Flat creation mode:</p><pre>book := Book{<br>    Title: &quot;Pop Book&quot;, Description: &quot;Pop Book&quot;, Isbn: &quot;PB1&quot;<br>}<br>tx.Create(&amp;book)</pre><pre>song := Song{Title: &quot;Don&#39;t know the title&quot;}                                            tx.Create(&amp;song)</pre><pre>addr := Address{HouseNumber: 1, Street: &quot;Golang&quot;}<br>tx.Create(&amp;addr)</pre><pre>user := User{<br>    Name: &quot;Mark Bates&quot;,<br>    Books: Books{Book{ID: book.ID}},<br>    FavoriteSong: song,<br>    Houses: Addresses{<br>        addr<br>    },<br>}</pre><pre>err := tx.Create(&amp;user)</pre><h4>Associations Pointer Support</h4><p>You can now use pointers on your associations:</p><pre>type Body struct {<br>    ID   int   `json:&quot;id&quot; db:&quot;id&quot;`<br>    Head *Head `json:&quot;head&quot; has_one:&quot;head&quot;`<br>}</pre><pre>type Head struct {<br>    ID     int   `json:&quot;id,omitempty&quot; db:&quot;id&quot;`<br>    BodyID int   `json:&quot;-&quot; db:&quot;body_id&quot;`<br>    Body   *Body `json:&quot;body,omitempty&quot; belongs_to:&quot;body&quot;`<br>}</pre><h4>Better CockroachDB Support</h4><p>Until now, CockroachDB tests were run by hand on local machines. We introduced CI testing in this version, and it helped to fix several bugs in Fizz and Pop.</p><p>SSL mode is now supported, and Truncate works on CockroachDB v2.</p><pre>development:<br>  dialect: cockroach<br>  options:<br>    sslmode: enable<br>    sslrootcert: &quot;/path/to/root/cert&quot;<br>    sslcert: &quot;/path/to/ssl/cert&quot;<br>    sslkey: &quot;/path/to/ssl/key&quot;</pre><h4>Options Changes</h4><p>In this version, we started to rework drivers options for more transparency:</p><ul><li>The encoding config key is deprecated, and moved to a collation option.</li><li>The new readTimeout option allows you to configure the connection read timeout. <strong>This is only available for MySQL now, but will be added for the other drivers in the next version</strong>.</li><li>parseTime and multiStatements: these options (MySQL only) were hardcoded, and are now visible in the configuration. <strong>Please note the first one is required to work with timestamps, and the second one is mandatory to work with migrations.</strong></li></ul><p>Here is a sample config for MySQL, showing the new options in action:</p><pre>development:<br>  dialect: mysql<br>  options:<br>    collation: utf8mb4_general_ci<br>    readTimeout: 1s<br>    parseTime: true<br>    multiStatements: true</pre><h4>Bugfix for Empty Insert</h4><p>There was a bug in Pop preventing a struct like the following to be saved:</p><pre>type IncrementalID struct { <br>    ID int `db:&quot;id&quot;`<br>}</pre><p>Since the ID is auto-generated by the database here, Pop don’t set the value in the SQL INSERT query. This mean the produced query for such a struct was something like that:</p><pre>INSERT INTO incremental_id () VALUES()</pre><p>While this is valid for MySQL, other databases don’t understand this syntax. This is now fixed in Pop v4.9.0.</p><h4>Pop Documentation Moved</h4><p>Pop official documentation is no longer in the README of the repo, since it’s difficult to maintain and to translate. We hope the new README is clearer.</p><p>You can now find the documentation on the gobuffalo.io website: <a href="https://gobuffalo.io/docs/db/getting-started">https://gobuffalo.io/docs/db/getting-started</a>. Feel free to contribute!</p><p>Thanks to the design team at <a href="https://wawand.co/">Wawandco</a>, we also have a new cute logo!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*43GncPPKZ2lzY3oi3U4lwA.png" /></figure><p>I hope you’ll enjoy this new version! Feel free to<a href="https://github.com/gobuffalo/pop/issues"> open an issue</a> if you find a bug, or ask for support on the <a href="https://gobuffalo.io/en/docs/slack">buffalo Slack channel</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77eeb63ff66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/pop-v4-9-0-released-77eeb63ff66">Pop v4.9.0 Released!</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pop v4.8.0 Released!]]></title>
            <link>https://medium.com/gobuffalo/pop-v4-8-0-released-f88725cd9ec9?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f88725cd9ec9</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[gobuffalo]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[orm]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Mon, 01 Oct 2018 18:30:21 GMT</pubDate>
            <atom:updated>2020-08-11T06:36:35.439Z</atom:updated>
            <content:encoded><![CDATA[<p>Better CLI validation, support for binary ID and more. Discover the new Pop release!</p><p>In addition to what is listed here, I recommend you read the <a href="https://github.com/gobuffalo/pop/releases/tag/v4.8.0">CHANGELOG</a> for a complete list of what has changed in v4.8.0.</p><h3>How to Upgrade</h3><h4>Standalone</h4><p>First, if you use soda without the Buffalo integration, you can upgrade the binary from source, using go get:</p><pre>$ go get -u -v github.com/gobuffalo/pop/soda</pre><p>You can also download a pre-built binary at:<br><a href="https://github.com/gobuffalo/pop/releases/tag/v4.8.0">https://github.com/gobuffalo/pop/releases/tag/v4.8.0</a></p><h4>Buffalo version</h4><p>If you use the Buffalo integration, you’ll have to upgrade the buffalo binary to use this version:</p><pre>$ go get -u -v github.com/gobuffalo/buffalo/buffalo</pre><p>For both versions, if you are using dep, and you pinned Pop to a specific version, you should change the version in Gopkg.toml to v4.8.0. Then run dep ensure -update to update your dependencies.</p><p>Otherwise, just run dep ensure -update to update your dependencies.</p><h4>Go Modules (beta)</h4><p>You can use Pop with Go modules:</p><p>go.mod:</p><pre>module github.com/gobuffalo/pop-test</pre><pre>require (<br>    github.com/gobuffalo/pop v4.8.0<br>)</pre><h3>What’s New</h3><h4>Better CLI validation</h4><p>To create a new model using soda, you can use the following command:</p><pre>soda generate model object name:string price:float</pre><p>It’s easy to make mistakes when typing the arguments for this command: from a beginner point of view, you’ll probably test the command with random stuff to understand what you can do and what you can’t.</p><p>Now, soda provides validation for the model generation command. You can no longer type something like that without having an error:</p><pre>soda generate model object name,price</pre><pre>soda generate model object name name</pre><pre>soda generate model object 1</pre><pre>soda generate model object name-test</pre><h4>Binary ID support</h4><p>Since <a href="https://blog.gobuffalo.io/pop-v4-6-0-released-bc9dc8f5eacb">v4.6.0</a>, pop provides support for string IDs. Now you can use binary IDs too.</p><h4>multiStatements required for MySQL</h4><p>The <strong>multiStatements</strong> option is now required if you use a custom URI with the MySQL driver.</p><p>Without this option, pop can’t understand migrations which contain more than one SQL statement.</p><pre>mysql:<br>    dialect: &quot;mysql&quot;<br>    url: &quot;root:pass@(127.0.0.1:3306)/pop_test?parseTime=true&amp;multiStatements=true&amp;readTimeout=1s&amp;collation=utf8mb4_general_ci&quot;</pre><p>I hope you’ll enjoy this new version! Feel free to<a href="https://github.com/gobuffalo/pop/issues"> open an issue</a> if you find a bug, or ask for support on the <a href="https://gobuffalo.io/en/docs/slack">buffalo Slack channel</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f88725cd9ec9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/pop-v4-8-0-released-f88725cd9ec9">Pop v4.8.0 Released!</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pop v4.7.0 Released!]]></title>
            <link>https://medium.com/gobuffalo/pop-v4-7-0-released-91869ac5921?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/91869ac5921</guid>
            <category><![CDATA[orm]]></category>
            <category><![CDATA[gobuffalo]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Sat, 25 Aug 2018 15:11:28 GMT</pubDate>
            <atom:updated>2020-08-11T06:36:56.974Z</atom:updated>
            <content:encoded><![CDATA[<p>Better logging, Go modules, UNIX timestamps and more. Discover the new Pop release!</p><p>In addition to what is listed here, I recommend you read the <a href="https://github.com/gobuffalo/pop/releases/tag/v4.7.0">CHANGELOG</a> for a complete list of what has changed in v4.7.0.</p><h3>How to Upgrade</h3><h4>Standalone</h4><p>First, if you use soda without the Buffalo integration, you can upgrade the binary from source, using go get:</p><pre>$ go get -u -v github.com/gobuffalo/pop/soda</pre><p>You can also download a pre-built binary at:<br><a href="https://github.com/gobuffalo/pop/releases/tag/v4.7.0">https://github.com/gobuffalo/pop/releases/tag/v4.7.0</a></p><h4>Buffalo version</h4><p>If you use the Buffalo integration, you’ll have to upgrade the buffalo binary to use this version:</p><pre>$ go get -u -v github.com/gobuffalo/buffalo/buffalo</pre><p>For both versions, if you are using dep, and you pinned Pop to a specific version, you should change the version in Gopkg.toml to v4.7.0. Then run dep ensure -update to update your dependencies.</p><p>Otherwise, just run dep ensure -update to update your dependencies.</p><h4>Go Modules (beta)</h4><p>You can use Pop with Go modules:</p><p>go.mod:</p><pre>module github.com/gobuffalo/pop-test</pre><pre>require (<br>    github.com/gobuffalo/pop v4.7.0<br>)</pre><h3>What’s New</h3><h4>Better logging</h4><p>Pop logging was a bit difficult to handle before this version: everything was considered as debug traces, some traces were not configurable at all, …</p><p>In v4.7.0, the Pop logger was refactored to solve these problems! The old logger signature still works, but you’re encouraged to migrate to the new one. If you use Buffalo and you didn’t customize the default logger, you can wait for Buffalo v0.13.0: we will migrate to the new logger in this version.</p><p>The legacy logger signature was:</p><pre>func(s string, args …interface{})</pre><p>The new one is:</p><pre>func(lvl logging.Level, s string, args …interface{})</pre><p>Available logging levels are (from the less verbose to the most verbose):</p><ul><li>Warn</li><li>Info</li><li>Debug</li><li>SQL</li></ul><h4>Go modules</h4><p>Pop v4.7.0 is the first minor release to introduce <strong>beta</strong> Go modules support. We’re still working on it, but it should work now.</p><p>If you prefer to stay on the v4.6.0 series, you can pick the <a href="https://github.com/gobuffalo/pop/releases/tag/v4.6.9">v4.6.9</a> release which also support Go modules and introduces some backported bug fixes.</p><h4>UNIX timestamps</h4><p>If you define the CreatedAt and UpdatedAt fields in your model struct (and they are created by default when you use the model generator), Pop will manage them for you. It means when you create a new entity in the database, the CreatedAt field will be set to the current datetime, and UpdatedAt will be set each time you update an existing entity.</p><p>These fields are defined as time.Time, but now you can define them as int and handle them as UNIX timestamps.</p><pre>type User struct {<br>  ID        int    `db:&quot;id&quot;`<br>  CreatedAt int    `db:&quot;created_at&quot;`<br>  UpdatedAt int    `db:&quot;updated_at&quot;`<br>  FirstName string `db:&quot;first_name&quot;`<br>  LastName  string `db:&quot;last_name&quot;`<br>}</pre><p>If you use fizz migrations, make sure to define these fields by yourself, and disable the default datetime timestamps:</p><pre>create_table(“users”) {<br>  t.Column(&quot;id&quot;, &quot;int&quot;, {primary: true})<br>  t.Column(“created_at”, “int”)<br>  t.Column(“updated_at”, “int”)<br>  t.Column(“first_name”, “string”)<br>  t.Column(“last_name”, “string”)<br>  t.DisableTimestamps()<br>}</pre><p>I hope you’ll enjoy this new version! Feel free to<a href="https://github.com/gobuffalo/pop/issues"> open an issue</a> if you find a bug, or ask for support on the <a href="https://gobuffalo.io/en/docs/slack">buffalo Slack channel</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91869ac5921" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/pop-v4-7-0-released-91869ac5921">Pop v4.7.0 Released!</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pop v4.6.0 Released!]]></title>
            <link>https://medium.com/gobuffalo/pop-v4-6-0-released-bc9dc8f5eacb?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc9dc8f5eacb</guid>
            <category><![CDATA[orm]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[gobuffalo]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 18:35:43 GMT</pubDate>
            <atom:updated>2020-08-11T06:37:11.851Z</atom:updated>
            <content:encoded><![CDATA[<p>String ID support, custom MySQL encoding and more. Discover the new Pop release!</p><p>In addition to what is listed here, I recommend you read the <a href="https://github.com/gobuffalo/pop/releases/tag/v4.6.0">CHANGELOG</a> for a complete list of what has changed in v4.6.0.</p><h3>How to Upgrade</h3><h4>Standalone</h4><p>First, if you use soda without the Buffalo integration, you can upgrade the binary from source, using go get:</p><pre>$ go get -u -v github.com/gobuffalo/pop/soda</pre><p>You can also download a pre-built binary at:<br><a href="https://github.com/gobuffalo/pop/releases/tag/v4.6.0">https://github.com/gobuffalo/pop/releases/tag/v4.6.0</a></p><h4>Buffalo version</h4><p>If you use the Buffalo integration, you’ll have to upgrade the buffalo binary to use this version:</p><pre>$ go get -u -v github.com/gobuffalo/buffalo/buffalo</pre><p>For both versions, if you are using dep, and you pinned Pop to a specific version, you should change the version in Gopkg.toml to v4.6.0. Then run dep ensure -update to update your dependencies.</p><p>Otherwise, just run dep ensure -update to update your dependencies.</p><h3>What’s New</h3><h4>String ID support</h4><p>In SQL world, primary keys are a way to fetch data using an unique indexed key. Pop has support for both int and UUIDs as primary keys for a long time, but using a string for that purpose wasn’t possible.</p><p>String primary keys are not often used, because they are more expensive to process; but sometimes they’re still useful.</p><p>Starting from v4.6.0, you can now use strings as IDs in pop:</p><pre>type Label struct {<br>    ID string `db:&quot;id&quot;`<br>}</pre><pre>// Create a new Label with a string ID<br>label := Label{ID: &quot;red&quot;}                                            err := tx.Create(&amp;label)</pre><h4>Custom MySQL encoding</h4><p>MySQL UTF-8 implementation <a href="https://mysqlserverteam.com/mysql-8-0-collations-the-devil-is-in-the-details/">is buggy</a>. Due to the way the data is stored using this encoding, parts of the UTF-8 chars are not supported.</p><p>To solve this problem, pop will generate new MySQL configs with a default encoding set to utf8mb4_general_ci, using the new “encoding” option (MySQL configs only):</p><pre>development:<br>    dialect: &quot;mysql&quot;<br>    database: &quot;coke_development&quot;<br>    host: &quot;localhost&quot;<br>    port: &quot;3306&quot;<br>    user: &quot;root&quot;<br>    password: &quot;root&quot;<br>    encoding: &quot;utf8mb4_general_ci&quot;</pre><p>In this version, utf8_general_ci is still used as the default encoding, so your app won’t break if you use it. You’ll see a warning about this issue, and the defaults will be switched to utf8mb4_general_ci in a later release.</p><h4>Improved database reset</h4><p>The soda tool provides a soda migrate reset command to reset the database schema to the initial current state. This command is now deprecated, and is replaced by a more powerful version: soda reset</p><p>This new version will try to recreate the database from the schema.sql file, so you don’t need to wait for all the patches to be applied. If this file can’t be found, it will fallback to migrations, just like soda migrate reset.</p><p>This command creates entries for the applied patches, so you still can reset the schema and apply new patches.</p><h4>Better EXISTS performances</h4><p>Pop Exists used to be a SQL COUNT, which can be slow for large tables. It uses a standard SQL EXISTS now, which stops after finding at least one entry.</p><p>I hope you’ll enjoy this new version! Feel free to<a href="https://github.com/gobuffalo/pop/issues"> open an issue</a> if you find a bug, or ask for support on the <a href="https://gobuffalo.io/en/docs/slack">buffalo Slack channel</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc9dc8f5eacb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/pop-v4-6-0-released-bc9dc8f5eacb">Pop v4.6.0 Released!</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pop v4.5.9 Released!]]></title>
            <link>https://medium.com/gobuffalo/pop-v4-5-9-released-f8e3461dbe81?source=rss-7ac2946019f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8e3461dbe81</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[gobuffalo]]></category>
            <dc:creator><![CDATA[Stanislas Michalak]]></dc:creator>
            <pubDate>Mon, 21 May 2018 21:39:00 GMT</pubDate>
            <atom:updated>2020-08-11T06:37:23.736Z</atom:updated>
            <content:encoded><![CDATA[<p>Partial selection, custom ID for belongs_to associations, and more. Discover the new Pop release!</p><p>In addition to what is listed here, I recommend you read the <a href="https://github.com/gobuffalo/pop/releases/tag/v4.5.9">CHANGELOG</a> for a complete list of what has changed in v4.5.9.</p><h3>How to Upgrade</h3><h4>Standalone</h4><p>First, if you use soda without the Buffalo integration, you can upgrade the binary from source, using go get:</p><pre>$ go get -u -v github.com/gobuffalo/pop/soda</pre><p>You can also download a pre-built binary at:<br><a href="https://github.com/gobuffalo/pop/releases/tag/v4.5.9">https://github.com/gobuffalo/pop/releases/tag/v4.5.9</a></p><h4>Buffalo version</h4><p>If you use the Buffalo integration, you’ll have to upgrade the buffalo binary to use this version:</p><pre>$ go get -u -v github.com/gobuffalo/buffalo/buffalo</pre><p>For both versions, if you are using dep, and you pinned Pop to a specific version, you should change the version in Gopkg.toml to v4.5.9. Then run dep ensure -update to update your dependencies.</p><p>Otherwise, just run dep ensure -update to update your dependencies.</p><h3>What’s New</h3><h4>Partial selection</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtdKFpdlQQ3yt5synKZZMA.jpeg" /></figure><p>Pop allows you to load the results from a query into a given struct. But what if you want to get only some fields of the model, and not the whole thing?</p><p>Thanks to <a href="https://github.com/larrymjordan">Larry M Jordan</a>, you can now use the new Select feature to solve this problem!</p><pre>type User struct {<br> ID           int           `db:&quot;id&quot;`<br> Email        string        `db:&quot;email&quot;`<br> Name         nulls.String  `db:&quot;name&quot;`<br> CreatedAt    time.Time     `db:&quot;created_at&quot;`<br> UpdatedAt    time.Time     `db:&quot;updated_at&quot;`<br>}</pre><pre>type Users []User</pre><pre>users := Users{}</pre><pre>// Select only email and name fields<br>err = db.Select(&quot;email&quot;, &quot;name&quot;).All(&amp;users)</pre><h4>Custom ID for belongs_to associations</h4><p>Since <a href="https://github.com/markbates/pop/releases/tag/v3.60.6">v3.60.6</a>, Pop gained the ability to manage models associations. This means you don’t need to query each dependent object by yourself, but Pop is able to retrieve them using custom tags.</p><p>In the database design theory, you can distinct 3 kinds of relations:</p><ul><li>1 to 1 (for instance, a soda has one, and only one brand).</li><li>1 to n (a brand produces one or more sodas).</li><li>n to n (a shop has a contract with each soda provider, but this contract can change, so it’s a new contract between the two entities).</li></ul><p>Thanks to <a href="https://github.com/u007">James</a>, you can now customize the field to use as a reference for belongs_to associations (1 to 1), using the fk_id tag.</p><pre>type Brand struct {<br> ID        int       `db:&quot;id&quot;`<br> Name      string    `db:&quot;name&quot;`<br> CreatedAt time.Time `db:&quot;created_at&quot;`<br> UpdatedAt time.Time `db:&quot;updated_at&quot;`<br>}</pre><pre>type Soda struct {<br> ID        int       `db:&quot;id&quot;`<br> CorpID    int       `db:&quot;corp_id&quot;`<br> Corp      Brand     `belongs_to:&quot;brand&quot; fk_id:&quot;CorpID&quot;`<br> CreatedAt time.Time `db:&quot;created_at&quot;`<br> UpdatedAt time.Time `db:&quot;updated_at&quot;`<br>}</pre><p>This will help if you’re working with a <strong>legacy database</strong> with different conventions, or if you want to <strong>reference the same model more than once</strong>, but with a different business meaning and a different value (think about a system asking for two persons in charge of a child. They are both Human, but have a different role in many systems).</p><p>A last note, on the project management: until now, each PR was merged into the master branch, so in cases of regressions, a bug fix must be released in a short amount of time.</p><p>So starting from today, Pop will follow the same schema as Buffalo: the master branch still handles the releases, but you’ll expect more stability. The PRs will be merged into a development branch instead, and tested as an edge version, with no stability guarantees, until the release.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8e3461dbe81" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gobuffalo/pop-v4-5-9-released-f8e3461dbe81">Pop v4.5.9 Released!</a> was originally published in <a href="https://medium.com/gobuffalo">Buffalo — Rapid Web Development in Go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>