adam_0628
adam_0628

Reputation: 137

Why does rails database id keep counting forward after destroying an intermediate item?

The title might not be so clear, and anyway it's better to just look at this:

My sequence of creating/destroying items A, B and C is:

  1. Create A --> id:1
  2. Create B --> id:2
  3. Destroy B
  4. Create C --> id:3

I've already destroyed B, C should be counted as id:2 right?

Upvotes: 3

Views: 201

Answers (1)

Jeff Paquette
Jeff Paquette

Reputation: 7127

The underlying database column for id is set to autoincrement. The id is generated at the database level, not by ActiveRecord. If you want to know more, read up on SQL sequences or autoincrement .

Upvotes: 6

Related Questions