title: Rails - how to group/map records from database into a string?
body: <p>I fetch data from database and they have this structure:</p>
  
  <pre><code>@articles = Article.where(...)
  </code></pre>
  
  <p>in <code>@data</code>:</p>
  
  <pre><code>id | author_id | article_name | ...
  1  | 1         | Morning      | ...
  2  | 1         | Wednesday    | ...
  3  | 2         | Hallo!       | ...
  </code></pre>
  
  <p>When I need to find out how many articles does have an author, I do it this way:</p>
  
  <pre><code>&lt;% articles = Hash[@articles.group_by(&amp;:author_id).map {|k,v| [k,v.length]}] %&gt;
  &lt;% @data.uniq_by {|x| x["author_id"]}.each do |result| %&gt;
    &lt;%= articles[result.author_id] %&gt;
  </code></pre>
  
  <p>But I would need to also fetch similarly also article names and access to them the same way as to the count of articles.
  I would need something like this:</p>
  
  <pre><code>&lt;%= articles2[result.author_id] %&gt; # and this would print out "Morning,Wednesday" for the author with ID 1
  </code></pre>
  
  <p>Which method should I use for this?</p>