我有评论模型:
class Comment
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :commentable, polymorphic: true, touch: true#, counter_cache: true
当我运行时:
Article.first.comments.count => 1 #without counter_cache: true
但是使用“counter_cache:true”我得到:
Article.first.comments.count => NoMethodError: undefined method
count' for nil:NilClass Article.first.comments => NoMethodError: undefined method
count' for nil:NilClass
有没有人遇到过这样的问题?