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

Problems with executing a scope in certain situations

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.5
    • Affects Version/s: None
    • Component/s: None
    • None

      I have a class that has a defined scope:

      class Reward
        scope :with_type, proc{|x| where(:_type => ( x == 'Reward' ? {'$ne' => 'SubReward'} : x ) ) }
        scope :with_person, proc{|x| where(:person_id => Moped::BSON::ObjectId(x.to_param))}
      end
      

      Which has problems executing the scope when I call it through an association:

      object.rewards.with_type("Reward")
      

      Or when I chain it after another scope:

      Reward.with_person(person).with_type("Reward")
      

      Both of these cases give me this error:

      NoMethodError:
             undefined method `update_values' for "Reward":String
      

      But works when I call it first on the class:

      Reward.with_type("Reward").with_person(person)
      

      Any ideas on why this might happen? I thought it might have to do with calling it on the class vs calling it on a Mongoid enumerable or Mongoid criteria?

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

              Created:
              Updated:
              Resolved: