Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
636 stars 200 forks source link

Strange error with autoincrement id #300

Closed thanosalexander closed 4 years ago

thanosalexander commented 6 years ago

I have a Post model and when i create a new one

App\Post::create([
     'body'=>'test'
])

i receive strange ids eg for past posts i have id 1186514 and for a newer one i have 1186487 which is lower , so i face huge problem in sorting

holix commented 6 years ago

Hey,

this is due to neo4j internal ids. As you can read here: https://stackoverflow.com/questions/30753560/should-we-use-the-neo4j-internal-id it is not recommended to use internal ids, as they can be reused, like it happened in your example. Obviously they are only reused after node/relationship is deleted.

You should either associate your own ids to nodes, and use them as autoincrement, or sort them using created_at column.

thanosalexander commented 6 years ago

Hi .. sure its a solution but it's not too much safe as maybe some other instance will be created at same time (second level).. so which one will be sorted first?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.