Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2929

Counter Cache with two parents doesn't initialise by default

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.3
    • Affects Version/s: None
    • Component/s: None
    • None

      I have User, Post, and Replies. When I create new Post the User gets updated and can be access from user.posts_count. But for replies, it doesn't see user.replies_count or post.replies_count. I must add Post.update_counters(post.id, replies_count: post.replies.count) then post.reload

      class User
        has_many :posts
        has_many :replies
      end
      
      class Post
        belongs_to :user, counter_cache: true
        has_many :replies
      end
      
      class Reply
        belongs_to :user, counter_cache: true
        belongs_to :post, counter_cache: true
      end
      

      Is there something I'm missing?

            Assignee:
            Unassigned Unassigned
            Reporter:
            seifsallam seifsallam
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: