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

Counter Cache with two parents doesn't initialise by default

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.3
    • Component/s: None
    • Labels:
      None

      Description

      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?

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: