我有以下 ActiveRecord 模型:
class User < ActiveRecord::Base
has_one :faculty
end
class Faculty < ActiveRecord::Base
belongs_to :head, class_name: 'User', foreign_key: :user_id
end
当我尝试使用此关联来拉用户时,faculty.head
我得到的记录没有错误,但是当我输入时,user.faculty
我得到一个错误:
Faculty Load (1.8ms) SELECT "faculties".* FROM "faculties" WHERE "faculties"."user_id" = 1 LIMIT 1
ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: operator does not exist: character varying = integer
LINE 1: ...".* FROM "faculties" WHERE "faculties"."user_id" = 1 LIMIT ...
我的faculties
数据库架构如下所示:
create_table "faculties", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "user_id"
end
这是一些PG错误吗?