Mongomapper scope concatenation

82 Views Asked by At

I'm experiencing strange behaviour with mongomapper scope concatenation.

Below an example.

I have two scopes:

 scope :active, where(
    :name =>
    {
      :$in =>
      Model2.active.distinct(:city)
    }
  )
  scope :by_htype_id, lambda{|htype_id|
      where(
        :name =>
        {
          :$in =>

            Model2.by_htype_id(htype_id).distinct(:city)

        }
      )
  }

If I run

Model1.by_htype_id("some_id") it works as expected

but if I concatenate the two scopes Model1.active.by_htype_id("some_id") I obtain all the result from the active scope while I would expect to obtain the subset of active scope that depends on by_htype_id

EDIT: If i write the concatenation of the scope as a single query it works as expected. I would expect the concatenation to result in and combination of the two scopes. As I said I'm having the problem just concatenating some scopes, not with every scope.

0

There are 0 best solutions below