-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
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