<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sofiane Baddag</title>
    <description>The latest articles on DEV Community by Sofiane Baddag (@popo63301).</description>
    <link>https://dev.to/popo63301</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F198748%2Fd1d46fa6-5abc-425b-9e1d-06264dfdc94a.jpg</url>
      <title>DEV Community: Sofiane Baddag</title>
      <link>https://dev.to/popo63301</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/popo63301"/>
    <language>en</language>
    <item>
      <title>Fast Ordered Model in Phoenix with ecto_list</title>
      <dc:creator>Sofiane Baddag</dc:creator>
      <pubDate>Sun, 21 Jul 2019 09:59:39 +0000</pubDate>
      <link>https://dev.to/popo63301/fast-ordered-model-in-phoenix-with-ectolist-25g7</link>
      <guid>https://dev.to/popo63301/fast-ordered-model-in-phoenix-with-ectolist-25g7</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbzuet43fkt64iwibkfb7.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbzuet43fkt64iwibkfb7.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;I was coding a paid video service with a system of Serie/Video. A serie has several videos ordered according to a defined order. &lt;br&gt;
I was surprised by how longer it took me to build this feature and by the lack of solution provided by the community. As I realized that I may encounter this problem again, say, if I build a Trello clone, I thought I have to do something. &lt;/p&gt;

&lt;p&gt;Here comes ecto_list ! &lt;/p&gt;

&lt;h2&gt;
  
  
  What?
&lt;/h2&gt;

&lt;p&gt;Ecto_list is both a library and a tutorial with a set of snippets that helps you build ordered model with Ecto rapidly. No LiveView involved ! &lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work?
&lt;/h2&gt;

&lt;p&gt;There is 2 ways to save the order of items: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;in the items themselves (like &lt;code&gt;act_as_list&lt;/code&gt; Ruby gem) : i.e. the Videos&lt;/li&gt;
&lt;li&gt;in the model they belong to: i.e. the Serie.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ecto_list takes the latter option. Why ? Because we want to avoid making several SQL query to update all ordering for one item only and, also, &lt;strong&gt;we assume we preload all the items anyway&lt;/strong&gt;. That’s why it makes sense to save the order in the model that has many items.&lt;/p&gt;

&lt;p&gt;This library is super easy to understand. There is one function at the moment that does the magic of ordering the items according to a defined order: &lt;code&gt;EctoList.ordered_items_list/2&lt;/code&gt; . The rest is adding the right snippets at the right parts of the source code. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This is my first library ever ( &lt;em&gt;yeaah!&lt;/em&gt; 🎉). There is still room for improvements so if you think we can add some interesting features, feel free to contribute. &lt;/p&gt;

&lt;h3&gt;
  
  
  Links:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;ecto_list: &lt;a href="https://github.com/popo63301/ecto_list/" rel="noopener noreferrer"&gt;https://github.com/popo63301/ecto_list/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;ecto_list_demo: &lt;a href="https://github.com/popo63301/ecto_list_demo" rel="noopener noreferrer"&gt;https://github.com/popo63301/ecto_list_demo&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>elixir</category>
      <category>phoenix</category>
      <category>ecto</category>
    </item>
  </channel>
</rss>
