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

count behaviour in embedded docs

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I have this model:

      class Comment
      include Mongoid::Document
      include Mongoid::Timestamps

      field :name
      field :text
      field :published, :type => Boolean, :default => false

      embedded_in :commentable, :inverse_of => :comments
      validates_presence_of :name, :text

      scope :pending, where(:published => false)
      scope :published, where(:published => true)
      end

      So when I do this:

      commentable.comments.published.count # => 3
      commentable.comments.pending.count # => 3
      commentable.comments.published.size # => 1
      commentable.comments.pending.size # => 2

      count doesn't filter, and returns the total of comments.
      To filter I have to use size() instead of count().

      Is this the expected behaviour?

            Assignee:
            Unassigned Unassigned
            Reporter:
            Papipo Rodrigo Alvarez [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: