2
我的狀態模型看起來是這樣的:PostgreSQL特有的數據庫錯誤: 「的ActiveRecord :: StatementInvalid:PGError:ERROR:運營商不存在」
class State < ActiveRecord::Base
belongs_to :country
named_scope :order_by_name, :order => :name
validates_presence_of [:country, :name]
def <=>(other)
name <=> other.name
end
end
我國模型是這樣的:
class Country < ActiveRecord::Base
has_many :states
named_scope :order_by_name, :order => :name
def <=>(other)
name <=> other.name
end
end
這個工作在SQLite的環境:
>> Country.find_by_iso("US").states
=> [#<State id: 1, name: "Alaska", abbr: "AK", # .....
但在PostgreSQL的環境中,我得到這個:
>> Country.find_by_iso("US").states
ActiveRecord::StatementInvalid: PGError: ERROR: operator does not exist: character varying = integer
LINE 1: SELECT * FROM "states" WHERE ("states".country_id = 214)
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT * FROM "states" WHERE ("states".country_id = 214)
有什麼想法?
提問並回答。 – tpdi 2009-04-17 07:22:18