Ruby on rails 使用Rails 3.0.9和Ruby 1.8.7的Mongoid 2.2中的范围链接

Ruby on rails 使用Rails 3.0.9和Ruby 1.8.7的Mongoid 2.2中的范围链接,ruby-on-rails,ruby,mongoid,scoping,Ruby On Rails,Ruby,Mongoid,Scoping,您好,我的应用程序运行在Ruby 1.8.7上,我目前无法将其更新为1.9.2和运行mongoid 2.2.2的Rails 3.0.9 我有两个命名的作用域,我定义如下 scope :for_pickups, where(:state => "accepted") scope :confirmed_shipments, where(:state => "confirmed", :created_at.lt => Date.today - 1.day).desc(:created_at).li

您好,我的应用程序运行在Ruby 1.8.7上,我目前无法将其更新为1.9.2和运行mongoid 2.2.2的Rails 3.0.9

我有两个命名的作用域,我定义如下



scope :for_pickups, where(:state => "accepted")
scope :confirmed_shipments, where(:state => "confirmed", :created_at.lt => Date.today - 1.day).desc(:created_at).limit(10)
scope :undelivered_shipments, Proc.new{ |start_date_utc, end_date_utc|
                                  start_date_utc = (Date.today - 7.days).to_time.utc if !start_date_utc.present?
                                  end_date_utc = Date.today.to_time.utc if !end_date_utc.present?
                                  any_of({:created_at.gte => start_date_utc, :created_at.lte => end_date_utc}, 
                                         {:pickup_date.gte => start_date_utc, :pickup_date.lte => end_date_utc}, 
                                         {:desired_arrival_date.gte => start_date_utc, :desired_arrival_date.lte => end_date_utc}).
                                  where(:state.in => ["accepted"], :state.nin => ["delivered"]).without(:carrier_digest, :carrier_label_image_base64, :carrier_label_html_base64)
                                }

scope :search, Proc.new{|search_params| 
                    regexp = Regexp.new(/.*#{search_params.strip}.*/i, true)
                    where(:golfer_name => regexp)
                  }
当我单独使用它们时,这似乎工作得很好,并返回预期值,但当我使用范围链接时,它会变得一团糟

例如,当我运行Model.undelivered\u shippings.searchsid时,我得到一个数组,该数组的第一个参数是:ids


[:ids, #[{:created_at=>{"$gte"=>Thu Sep 27 18:30:00 UTC 2012, "$lte"=>Thu Oct 04 18:30:00 UTC 2012}}, {:pickup_date=>{"$gte"=>Thu Sep 27 18:30:00 UTC 2012, "$lte"=>Thu Oct 04 18:30:00 UTC 2012}}, {:desired_arrival_date=>{"$gte"=>Thu Sep 27 18:30:00 UTC 2012, "$lte"=>Thu Oct 04 18:30:00 UTC 2012}}], :_id=>"sid", :state=>{"$nin"=>["delivered"], "$in"=>["accepted"]}},
  options:  {:fields=>{:carrier_digest=>0, :carrier_label_html_base64=>0, :carrier_label_image_base64=>0}},
  class:    Shipment,
  embedded: false>
]
不确定它为什么返回此值以及为什么mongoid条件定义:_id=>'sid',但是,当我在undelivered方法之前运行搜索时,它会正确生成条件

如果将其与其他作用域一起运行,例如用于_pickups.search等,但不与未交付的装运一起运行,则该功能可以正常工作。我知道我遗漏了一些东西,但我已经查阅了文档,找不到任何真正有用的东西。我真的非常感谢你在这方面的帮助

提前谢谢