0

I'm using rails 4.2 & postgresql and I'm working on existing non rails DB. table schema is given below:

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

Issue is:

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

I'm using 2 extension postgis, plpgsql and Coutomer.count increasing properly.

I tried customer.reload its give me error.

output of customer instance variable

#<Customer CustomerNo: "P'::text || nextval('sqcustomer_no", CustomerOperatorId: nil, CustomerType: nil, BrokerId: nil, Address: nil, SalutationId: nil>

any idea why I'm getting this?

Thanks Neelesh

Neelesh
  • 1,458
  • 2
  • 13
  • 20

1 Answers1

0

In your model, have you told Rails that the primary key column is CustomerNo, not id?

class Customer < ActiveRecord::Base
  set_primary_key :customer_no
  ...
end
David Aldridge
  • 51,479
  • 8
  • 68
  • 96