0
如何設置深度超過兩級的關聯?我有一個資源用戶has_one博客有許多職位,其中有許多評論has_one聯繫。已經有用戶has_may聯繫人。但是我怎麼辦呢?應該用戶have_many帖子:通過=>博客?或者我應該直接有Post參考用戶?模型四級深 - Rails 3
如何設置深度超過兩級的關聯?我有一個資源用戶has_one博客有許多職位,其中有許多評論has_one聯繫。已經有用戶has_may聯繫人。但是我怎麼辦呢?應該用戶have_many帖子:通過=>博客?或者我應該直接有Post參考用戶?模型四級深 - Rails 3
有了許多可能的直接關聯關係,您有很多選擇,並且沒有任何嚴格的規則。因此,設置你所需要的。你在協會中有很多深度,但是你真的想要user.posts,因爲他們會跨越不同的博客嗎?無論如何,我在下面添加了它。
class User
has_many :blogs
has_many :contacts, :through => :user_contacts
has_many :posts, :through => :blogs
class UserContacts
belongs_to :user
belongs_to :contact
class Blog
belongs_to :user
has_many :posts
class Post
belongs_to :blog
has_many :comments
class Comment
belongs_to :post
has_one :contact
class Contact
has_many :comments
謝謝你一堆。我最終修改了它,因爲每個用戶都有一個博客。 – AdamCooper86 2012-07-20 13:07:54