我有一个单表继承模型,如下所示:
class Application < ActiveRecord::Base
has_many :snapshots, :dependent => :destroy
has_many :foos, :dependent => :destroy
end
class Snapshot < ActiveRecord::Base
end
class Foo < Snapshot
end
Snapshot/Foo 类有一个日期变量名为 'when' 当我将 :order => 'when' (或 :when)添加到 has_many (foos) 关系时,数据库在我访问对象时会引发错误。例如 application.foos.each...
生成的查询:
SELECT "snapshots".* FROM "snapshots" WHERE "snapshots"."type" IN ('Foo') AND "snapshots"."application_id" = 25 ORDER BY when
*“当”附近的错误:语法错误
如果我手动编辑查询并将其输入到 rails dbconsole:
SELECT "snapshots".* FROM "snapshots" WHERE "snapshots"."type" IN ('Foo') AND "snapshots"."application_id" = 25 ORDER BY "snapshots"."when"
查询有效。
这是一个已知的 rails 3 错误还是有一些特殊的语法?任何解决方法?