Reputation: 4475
I have an existing Sqlite table that's got an id
column, but it's not the primary key. The primary key is named ROWID
.
So in my model I've done:
self.primary_key = "ROWID"
However, because the id
field actually has good data in, AR is overwriting that data when it instantiates the records with the value from ROWID
.
How do I go about preserving the value in the id
column, while indicating ROWID
is the primary key?
[6] pry(main)> Message.first.handle
D, [2015-09-14T08:58:59.250979 #921] DEBUG -- : Message Load (0.4ms) SELECT "message".* FROM "message" ORDER BY "message"."ROWID" ASC LIMIT 1
D, [2015-09-14T08:58:59.252343 #921] DEBUG -- : Handle Load (0.1ms) SELECT "handle".* FROM "handle" WHERE "handle"."ROWID" = ? LIMIT 1 [["ROWID", 8]]
=> #<Handle:0x007ff0f930c0e0 ROWID: 8, id: 8, country: "us", service: "iMessage", uncanonicalized_id: nil>
Upvotes: 2
Views: 113