ruby on rails奇怪计数错误

时间:2009-08-03 20:24:55

标签: ruby-on-rails

我正在尝试查找大于特定数据源数量的设备数量。

last_data_source = LocalDeviceSummary.find(:first, :order => 'created_at desc')
count = RemoteDeviceSummary.count ["DeviceSummaryIndex > ?", last_data_source.data_source_id]

last_data_source工作正常,我测试了。错误与计数有关。这是错误。

Mysql ::错误:您的SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在'?2896012附近使用正确的语法)AS count_devicesummaryindex_2896012第1行的device_summary':SELECT count(DeviceSummaryIndex>?2896012)AS count_devicesummaryindex_2896012 FROM {{1} }

1 个答案:

答案 0 :(得分:1)

将数组传递给ActiveRecord :: Count时,需要使用:conditions符号指定输入数组。这应该适合你:

count = RemoteDeviceSummary.count(:conditions => ["DeviceSummaryIndex > ?", last_data_source.data_source_id])