ruby-on-railsmongoidmongoid4

mongoid combination of any_of and between


I need to achieve something like:

queryable.any_of(
      between(:average_nightly_min_price,  [10,100]),
      between(:average_nightly_max_price,  [110,1100])
  )

is it possible using the combination of any_of and between. Or any other alternatives?


Solution

  • queryable.any_of(
      queryable.between(:average_nightly_min_price,  [10,100]).selector,
      queryable.between(:average_nightly_max_price,  [110,1100]).selector
    )
    

    It does not work if the queryable is embeded.

    For ruby versions prior 2.0:

    queryable.any_of(
          queryable.between(average_nightly_min_price => [10,100]).selector,
          queryable.between(average_nightly_max_price => [110,1100]).selector
        )