LaravelFreelancerNL/laravel-arangodb

Research conversion of _key to and from id.

Closed this issue · 3 comments

For package compatibility it is probably required to supply an id. ArangoDB uses both _id and _key. Where the latter has a SQL like structure as _id includes the collection.

Common problems and considerations:

  • Even though some packages allow you to override the models in use the relationships between them usually don't grab the model's keyname but assume 'id' regardless. This leads to more overriding/overloading than otherwise necessary.
    It's an illusion to think that new and existing packages will all start to grab the key name from the model.
  • A model's routeKey falls back to id. _id breaks routes due to the slash in its {collection}/{_key} structure. While the routeKey can be set separately this then leads to problems in other packages that assume the routekey is the id.
  • _id must remain available for graph queries
  • _key usage is slightly more performant than _id. So preferred by default.
  • an id attribute might be nested deeper within a document in which case it should not be convert to _key

Possible solution:

  • Query results need to be processed to convert _key to id
  • If a query requests specific columns any occurrence of 'id' directly on a document must be changed to _key before executing the query.
  • The model's primary key can then be reverted to Laravel's default: id.

If doable this should be the start of the first stable version 1.0.
Preferably combined with working tests for all documented & compatible DB related methods in the Eloquent & Query builders.

This is working quite nicely in the next branch and will be available in the next release