2016-11-04 3 views
0

私はrails 4.2 &のpostgresqlを使用しています。私は既存の非レールDBを作成しています。テーブルスキーマは、以下の通りである:作成したモデルインスタンスのPostgresのプライマリキーのデフォルト値は025です

# == 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 

問題がある:私はpostgis, plpgsqlCoutomer.countが適切に増加2拡張子を使用してい

customer = Customer.create! #successfully created 
customer.id #nil value 
customer.CustomerNo #nil value 

私はcustomer.reloadを試してみました。変数

#<Customer CustomerNo: "P'::text || nextval('sqcustomer_no", CustomerOperatorId: nil, CustomerType: nil, BrokerId: nil, Address: nil, SalutationId: nil> 
customerインスタンスの

出力

私はこれを取得していますなぜ任意のアイデア?お使いのモデルで

おかげ Neelesh

+0

ここには何もありませんか? http://stackoverflow.com/questions/5975081/camelcase-instead-of-snake-case-in-rails-db –

+0

@DavidAldridge私はしましたが、動作しませんでした。 – Neelesh

答えて

0

は、あなたがID、主キー列がCustomerNoであるレールのないように言わ持っていますか?

class Customer < ActiveRecord::Base 
    set_primary_key :customer_no 
    ... 
end 
+0

はい私はしましたself.primary_key = 'CustomerNo' – Neelesh

関連する問題