0

I'm connecting a Rails application to another database and can't change the schema. This other database has a NOT NULL constraint on the id field for all of its tables (using uuid for id's).

I'm trying to assign an id manually in a before_create but it seems the attribute is protected.

Any way around this?

Rails 5.0.0

fridgerator
  • 323
  • 7
  • 17
  • maybe one of these answers help -> http://stackoverflow.com/questions/431617/overriding-id-on-create-in-activerecord – neongrau Aug 24 '16 at 14:28
  • @neongrau I know I was able to manually set an id that way in <= 4.0, however in 5 it seems something has changed and this no longer works. – fridgerator Aug 24 '16 at 15:43
  • Is that a MSSQL database you are using? – neongrau Aug 25 '16 at 06:56
  • @neongrau It is postgres. It is actually a database created / used by a Django application. It seems he Django application assigns an id before save (uuid), whereas rails does not. – fridgerator Aug 26 '16 at 18:29

1 Answers1

0

Add a uid field to the new database and use find_by(uid: uid)

phillyslick
  • 571
  • 6
  • 12