Note that there are some explanatory texts on larger screens.

plurals
  1. POShowing data from multiple related tables
    primarykey
    data
    text
    <p>Using Rails 2.3.8. I wanna show data from complicated relationship.</p> <p>These are in my models:</p> <p><strong>shop.rb</strong></p> <pre><code>has_many :city_shops id | name 3 | Good Cafe </code></pre> <p><strong>city_shop.rb</strong></p> <pre><code>belongs_to :city belongs_to :shop id | city_id | shop_id | notes 2 | 4 | 3 | Delicious food in Paris </code></pre> <p><strong>city.rb</strong></p> <pre><code>belongs_to :article has_many :city_shops has_many :shops, :through =&gt; :city_shops id | article_id 4 | 5 </code></pre> <p><strong>article.rb</strong></p> <pre><code>has_many :shops, :through =&gt; :shop_articles has_many :cities, :dependent =&gt; :destroy id | user_id | name 5 | 6 | Favorite shops in France </code></pre> <p><strong>user.rb</strong></p> <pre><code>has_many :articles id | login 6 | victor </code></pre> <p>The scenario is this (may not be logical): A user with ID 6 creates many articles. Let's say he creates this article called <strong>Favorite shops in France</strong>. In this article, there are <code>cities</code>. In each <code>city</code>, there are <code>city_shops</code> where in it there are details <code>shop</code> and <code>notes</code> from <code>city_shops</code>. </p> <p>I also have individual <code>shop</code> page. I want the visitors to know what notes have been left by users, where the note is and the link to that user's article.</p> <p>In the <code>shop</code> page, it should read:</p> <p><strong>Notes by users</strong> "Delicious food in Paris" by "victor", shared in "link to favorite shops in France".</p> <p>I hope this question is clearer than previous. Thank you very much.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload