我使用的是rails 4.2& postgresql和我正在使用现有的非rails DB。表模式如下:
# == Schema Information
#
# Table name: customer
#
# CustomerNo :text default("P'::text || nextval('sqcustomer_no"), not null, primary key
# CustomerOperatorId :string(8)
# CustomerType :integer
# BrokerId :string(250)
# Address :text
# SalutationId :integer
问题是:
customer = Customer.create! #successfully created
customer.id #nil value
customer.CustomerNo #nil value
我正在使用2个分机postgis, plpgsql
和Coutomer.count
正常增加。
我试过customer.reload
它给我错误。
customer
实例变量
#<Customer CustomerNo: "P'::text || nextval('sqcustomer_no", CustomerOperatorId: nil, CustomerType: nil, BrokerId: nil, Address: nil, SalutationId: nil>
任何想法为什么我得到这个?
由于 Neelesh
答案 0 :(得分:0)
在你的模型中,你告诉Rails主键列是CustomerNo,而不是id?
SELECT DISTINCT t."BP Name"
FROM ( SELECT
"BP Name",
"Disbursment Date"
FROM "SB_MD"
WHERE year("Disbursment Date") = (Year(getdate()) -1)
) t LEFT JOIN( SELECT "BP Name"
FROM "SB_MD"
WHERE year("Disbursment Date") < (year(getdate()) -1)
) t1 ON t."BP Name" = t1."BP Name"
WHERE t1."BP Name" is null