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

excludes + gte, lte on DateTime not working correctly?

    XMLWordPrintable

    Details

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

      Description

      class Product < Inventory
      embeds_one :tag_new, autobuild: true, cascade_callbacks: true, class_name: "InventoryTag"
      end

      class InventoryTag
      field :enabled, type: Boolean, default: false
      field :limited, type: Boolean, default: false
      field :start_at, type: DateTime
      field :end_at, type: DateTime
      end

      I've got these three records:

      actual = #<InventoryTag enabled: true, limited: false, start_at: nil, end_at: nil>
      actual_with_date = #<InventoryTag enabled: true, limited: true, start_at: 2013-01-27 07:22:08 UTC, end_at: 2013-03-27 07:22:26 UTC>
      not_actual = #<InventoryTag enabled: true, limited: true, start_at: 2012-11-27 07:23:05 UTC, end_at: 2012-12-27 07:22:55 UTC>

      I would like to load all enabled tags (enabled == true), and actual tags (start_at < Time.now && end_at > Time.now, or start_at == && end_at == nil).

      My try:

      products = Product.where(:"tag_new.enabled" => true).excludes(:"tag_new.start_at".gte => Time.now, :"tag_new.end_at".lte => Time.now)
      products.include?(actual) # => true
      products.include?(actual_with_date) # => true
      products.include?(not_actual) # => true
      products.size # => 3 (should be 2)

      This query should return size == 2, but it return 3

        Attachments

          Activity

            People

            Assignee:
            durran Durran Jordan
            Reporter:
            palodelincak palodelincak
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: