2
我有一个简单的ActiveRecord对象,表示估计的到达时间。从ActiveRecord对象生成不正确的SQL的Rails
class Eta < ActiveRecord::Base
belongs_to :stop
belongs_to :vehicle
validates :timestamp, :presence => true
end
在我的数据库,我创建了相应的列stop_id
,vehicle_id
和timestamp (of type datetime)
。
我有一个rake任务设置为对此表执行操作,但它生成的SQL没有意义。如果我尝试运行:
for eta in Eta.all
puts eta.timestamp
end
它试图SELECT * FROM eta
,但是表被命名为etas
,不eta
。
复数数据库命名与从ActiveRecord对象创建的其余表格一致,并且我成功创建了一个可正常工作的类似ActiveRecord对象。
class PrecedingCoord < ActiveRecord::Base
belongs_to :stop
belongs_to :route
belongs_to :coord
end
在耙文件:
for eta in PrecedingCoord.all
puts eta.coord.latitude
end
哈哈哈哈......这一次让我大声笑...约定优于配置有偶尔打嗝 – tybro0103