I know that my problem is the trivial one, but I need some help.
I have two mongoid classes with has_many relation:
class Container
...
has_many: items
...
end
class Item
...
field :date, type => Date
belongs_to: container
...
end
I need all containers that have item at the particular date.
Here is the scope that doesn’t work as expected. It returns both, the containters that do have, and the containers that don’t have items at the given date:
class Container
...
scope :with_items_on, ->(date){ where(:_id.in => Item.on(date).only(:container_id).distinct(:container_id)) }
...
end
.on(date) is scope that returns correctly all Items for the given date.
Thanks.
Place.rb
has_many :reviewsReview.rb
belongs_to :placeMongoid 3 does not support it
Place.where('reviews.state' => 'published')