迁移到RAILS 4.2

时间:2015-10-29 17:41:28

标签: ruby-on-rails ruby-on-rails-4 rspec

我从Rails 3.x迁移到Rails 4.2

我有以下代码:

Order.all :conditions => ["flagged = ? AND orders_id != ? AND (
  delivery_name = ? OR
  delivery_telephone = ? OR
  email = ? OR
  ((delivery_address IS NOT NULL AND delivery_address != '') AND delivery_address = ?) OR
  (remote_ip IS NOT NULL AND remote_ip = ?)
  )",
  true,
  self.orders_id,
  self.delivery_name,
  self.delivery_telephone,
  self.email,
  self.delivery_address,
  self.remote_ip,
]

当我运行测试时,我得到以下的修复:

  

DEPRECATION WARNING:不推荐使用Relation#all。如果你想   急切加载关系,你可以调用#load(例如Post.where(published: true).load)。如果要从关系中获取记录数组,   一个>你可以拨打#to_a(例如Post.where(published: true).to_a)。 (称为   来自similar_flagged_orders at   /Users/fisnik/code/myr-admin/app/models/order.rb:173)

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

Order.where("flagged = ? AND orders_id != ? AND (
  delivery_name = ? OR
  delivery_telephone = ? OR
  email = ? OR
  ((delivery_address IS NOT NULL AND delivery_address != '') AND delivery_address = ?) OR
  (remote_ip IS NOT NULL AND remote_ip = ?)
  )",
  true,
  orders_id,
  delivery_name,
  delivery_telephone,
  email,
  delivery_address,
  remote_ip
)

从3.x直接升级到4.2是疯狂的,你不可避免地要努力使事情发挥作用。

Do it gradually

首先升级到3.2,然后升级到4.0,只有这里有2个选项 - 4.1和4.2。

逐步升级您的测试框架。