title: Ruby on rails 5 show all results depending on related table quantity
body: <p>I have 2 models, one is shop and the other is address. A shop has many addresses and an address belongs to a shop.</p>
  <p>I want to select (search) by name and filter all the shops that match with the search word and separated for each address, e.g. <code>search param[:name]</code>.</p>
  <pre><code>def filter_shops
       @shops = Shop.where(&quot;name ILIKE CONCAT('%',?,'%')&quot;,params[:name])
  end
  </code></pre>
  <p>This action searches all the shops by the param name, but I want that if a shop has 2 or 3 addresses it has to be shown in the result 2-3 times.</p>
  <p>Example (expected results):</p>
  <pre><code>params[:name] value is &quot;sho&quot;
  
  [{name: &quot;shopOne&quot;,
   address: {
       id: 1,
       direction: &quot;av. jojojo 321&quot;}
  
  },{name: &quot;shopOne&quot;,
       address: {
             id: 2,
          direction: &quot;onother avenue &quot;}},
   {name: &quot;shopTwo&quot;,
       address: {
             id: 7,
             direction: &quot;av. of other shop 333&quot;}
  }]
  </code></pre>