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 74 forks source link

Descendant entries not recognized in a multi-site setup #109

Closed piljac1 closed 1 year ago

piljac1 commented 1 year ago

Environment

Laravel Version: 9.48.0 PHP Version: 8.1.12 Composer Version: 2.1.6 Database: MySql 8.0.31 Statamic Version: 3.3.65 PRO

The issue

After following the "Storing Entries in a Database" docs (apart from the fact I use an auto-increment ID), I encountered an issue where creating a related (localized) entry would "work" as it is stored in the database, but would not be detected by Statamic (still showing a red dot by the other site's version of the entry). If you try to create the same related entry again, it creates a duplicate in the database and still is undetected by Statamic.

After debugging, I found out that both descendants and detachLocalizations (from the Statamic\Entries\Entry class) refer to origin in their queries where clauses instead of origin_id as specified in the suggested "Storing Entries in a Database" docs entries table migration. When replacing origin with origin_id, it seems to behave properly, but it is not as simple as that, since changing this could be breaking for other people setups.

Reproduction repo

P.S. My "hotfix" is applied in this repo, so if you want to see the actual bug, search for the descendants and detachLocalizations methods in app/Eloquent/Entries/Entry.php and comment them.

https://github.com/piljac1/statamic-eloquent-issues

ryanmitchell commented 1 year ago

Any reason why you aren't using https://github.com/statamic/eloquent-driver instead of rolling your own?

piljac1 commented 1 year ago

To be honest, no reason. I'm not that experienced with Statamic and just looked around the Statamic docs and searched for both "eloquent" and "database" and other than the Tips & Tricks articles like the one I stated, the Eloquent driver isn't stated anywhere. I assumed the eloquent-driver package was used by the CMS internally and that the Tips & Tricks articles leveraged what that driver added to the core. Guess I was wrong.

ryanmitchell commented 1 year ago

Yeah the docs could maybe be a bit more clear that the package exists. Give it a go, I think it'll solve both your issues.

piljac1 commented 1 year ago

Thanks, I'll try it out. Any limitation I should be aware of? Because I also want to have a standard relational database structure for data heavy tasks. Basically, does this driver function properly if I intend to use Runway for the heavy lifting and standard entries for stuff like pages and articles?

ryanmitchell commented 1 year ago

Yes it's a drop in replacement for flat files at this point.

ryanmitchell commented 1 year ago

Can you close this issue?