Tom*_*man 2 postgresql ruby-on-rails
我的州模型看起来像这样:
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
Run Code Online (Sandbox Code Playgroud)
我的国家模型看起来像这样:
class Country < ActiveRecord::Base
has_many :states
named_scope :order_by_name, :order => :name
def <=>(other)
name <=> other.name
end
end
Run Code Online (Sandbox Code Playgroud)
这适用于SQLite环境:
>> Country.find_by_iso("US").states
=> [#<State id: 1, name: "Alaska", abbr: "AK", # .....
Run Code Online (Sandbox Code Playgroud)
但是在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)
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
| 归档时间: |
|
| 查看次数: |
4244 次 |
| 最近记录: |