0

I'm writing a simple application using DataMapper. It is somewhat crucial that I maintain consistent IDs (serial property) in my database (which may change freely), so I wrote this simple script that goes through every record and fixes the IDs so that they stay consistent (e.g. 1, 2, 3...).

The problem is, every time I add a new record, it's added with a new ID that breaks the consistency - as if the previous records weren't fixed.

How can I prevent this behavior? Or rather, is there an easier way to maintain a logical progression of IDs? I have a distinct feeling I'm not supposed to alter the IDs by hand.

Nekkoru
  • 1,145
  • 2
  • 12
  • 18

1 Answers1

2

datamapper usually creates sequential ids but this sequence can differ from your "logical order".

Examples:

  • you create the strip-objects in another sequence then you want them to be ordered
  • you create provisional strip-objects (prototypes) and delete them again
  • ..

I think you should't try to force datamapper to use your ids then. Instead I recommend an extra field like "nekkoru_number" which you can calculate after your own ideas. In your case using a unique name instead of a number may be a good idea too.

Think also of use cases like

  • inserting an object later
  • reordering the objects
ovhaag
  • 1,168
  • 2
  • 9
  • 16