geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

Allow use of autoincrementing id fields for Postgres and MySQL #148

Closed salieri closed 1 year ago

salieri commented 10 years ago

Provide an option for Postgres and MySQL configurations to use autoincrementing (numeric) row IDs rather than UUIDs.

Configurable (defaults off) via the database adapter configuration object (e.g. geddy.config.db). Set autoincrement = true to activate. Configuration affects all tables of the adapter in question.

Not taking in account table creation yet. Will support if needed.

mde commented 10 years ago

This is a long-standing issue (see this long conversation over in the Geddy repo: https://github.com/mde/geddy/issues/452) There is ostensibly the support for auto-incrementing IDs (an autoIncrementId property on the base model object), but it's never been well documented or well supported.

It needs to be global to the entire instance of Model, since the 'id' field is a special field that's managed by the framework (a good example is foreign keys for associations).

I would absolutely love for this feature to work correctly and consistently. Do you suppose you could adjust this PR to work well with the global setting? (I realize this setting is problematic for NoSQL adapters like Mongo, but let's just say for simplicity's sake that only SQL adapters will ever flip it on.)

salieri commented 10 years ago

Will be happy to refactor.

mde commented 10 years ago

That would be fantastic. Definitely need some good tests for this, since it's off by default, and has been prone to breakage a lot in the past.

mde commented 10 years ago

Any progress on this?

Oh, that reminds me -- this needs to work for SQLite as well. All SQL adapters should behave the same if possible.

salieri commented 10 years ago

Will get back to you after crunch mode is over, give it a few weeks.

mde commented 10 years ago

Excellent. Lemme know if there's anything I need to do.