我正在尝试在this教程之后创建多对多关系,但遇到了一个问题。当我尝试访问@ friends.post时,我明白了:
SystemStackError: stack level too deep
from /Users/mattmoss/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/irb/workspace.rb:86
Maybe IRB bug!
以下是我用来创建关系的代码:
在帖子中:
has_many :friends, :through => :taggings, :source => :taggable, :source_type => "Friend"
has_many :taggings
在过帐中:
belongs_to :post
belongs_to :postable, :polymorphic => true
在朋友中:
has_many :posts, :through => :postings
has_many :postings, :through => :posttable, :source_type => "Friend"
当我打电话给friends.posts时,我收到上面列出的错误。
答案 0 :(得分:0)
您收到此错误是因为当您的朋友模型具有自我参照关系时
删除:source_type => "朋友"来自朋友has_many:贴子
has_many :posts, :through => :postings
has_many :postings, :through => :posttable