使用Rails 2.3.8。我想要显示来自复杂关系的数据。显示来自多个相关表格的数据
这些都是在我的模型:
shop.rb
has_many :city_shops
id | name
3 | Good Cafe
city_shop.rb
belongs_to :city
belongs_to :shop
id | city_id | shop_id | notes
2 | 4 | 3 | Delicious food in Paris
city.rb
belongs_to :article
has_many :city_shops
has_many :shops, :through => :city_shops
id | article_id
4 | 5
article.rb
has_many :shops, :through => :shop_articles
has_many :cities, :dependent => :destroy
id | user_id | name
5 | 6 | Favorite shops in France
user.rb
has_many :articles
id | login
6 | victor
的场景是该(可以不是逻辑的): 与ID 6所述的用户创建了许多文章。假设他创建了这篇名为的文章法国最受欢迎的商店。在这篇文章中,有cities
。在每个city
中,有city_shops
,其中有shop
和notes
的细节从city_shops
。
我也有个人shop
页面。我希望访问者知道用户留下了什么笔记,笔记的位置以及该用户文章的链接。
在shop
页面,它应该阅读:
说明用户 “美味食品在巴黎”的“胜利者”,“链接,在法国最喜欢的商店”共享。
我希望这个问题比以前更清楚。非常感谢你。
所以,你必须@shop并希望从关联模型显示的数据? – LapinLove404 2011-02-15 17:24:46
阅读本指南:http://guides.rubyonrails.org/association_basics.html应该帮助你管理协会。 – tjeden 2011-02-15 20:02:26
我修改了我的问题并提供了更多详细信息。你能再看一遍吗?谢谢! – Victor 2011-02-16 06:15:29