1

I've made some changes using the question I'd answered. I need to have 8 bytes on the Model id.

I need to change the id to a different unique number:

Product.where(title: "Foo").update_attributes(id: 123456789)
# NoMethodError: undefined method `to_sym' for nil:NilClass

I've tried few answers but still getting errors. Do you need to see each error based on which method used? I know this is caused by the 8 byte changes I've done. Have I done it the correct way? How to change the id?

Edit

For some strange and scary reason, I have to recreate the database for this to work:

Product.where(title: "Foo").update_all(id: 123456789)
Community
  • 1
  • 1
Sylar
  • 11,422
  • 25
  • 93
  • 166
  • Why do you need to change the `id` just because you've switched its type to `bigint`? – mu is too short Sep 02 '16 at 18:54
  • A product is pulled from x then save in my db, they that same product goes to y and save. I need y's id to match in local db so I update last save product with y's id. – Sylar Sep 02 '16 at 18:56
  • that makes no sense, the id is an auto-incrementing column so the value is created set by the db when you insert a row. You don't really ever change PK columns. – max Sep 02 '16 at 19:50
  • @max Correct but I need the `:limit` to be `8`. Also, I must be able to change to another unique number. Any other way? – Sylar Sep 02 '16 at 19:52
  • I think you'd be better off keeping your own `id`s separate from the external ones. So instead of trying to sync up your `id`s with theirs you'd have a separate `external_id` column that contained theirs. – mu is too short Sep 02 '16 at 21:13
  • @muistooshort Then that means I could no longer use relations. `Product.where(id: 1111).variants`. Then again I could, `Product.where(external_id: 1111).variants.where(external_id: 1111)` – Sylar Sep 02 '16 at 21:17
  • Why not? You'd link your tables together using your `id`s and only have to worry about their `id`s at the edges. – mu is too short Sep 02 '16 at 21:25
  • An example to test, please? – Sylar Sep 02 '16 at 21:27
  • is that an associated object? if not, you can just re-create it with a new id and delete the old object – Guy Dubrovski Sep 04 '16 at 10:03

0 Answers0