statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 73 forks source link

Set origin id on entry model #160

Closed jasonvarga closed 1 year ago

jasonvarga commented 1 year ago

When calling $entry->origin(null), also set the origin_id on the model.

Otherwise, subsequent calls to $entry->origin() will fall back to reading the origin_id on the model, leaving you no way to truly null it out.

This is necessary when you delete an entry and choose to "detach" the localizations. All of the descendant entries should get the origin removed. Before this PR, when you tried to do that, the origin just sticks around. You end up with an error when trying to delete an entry instead of it actually getting deleted.

By solving this, the removal of the origin_id foreign key constraint onDelete cascade in #100 shouldn't be an issue.