-
-
Notifications
You must be signed in to change notification settings - Fork 593
[6.x] Add methods to Entry/Term Repos #9815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I removed the createOrFirst method as Statamic does not throw an exception when the entry/term already exists. This means the method would always create/update and never just return the entry/term. |
|
@duncanmcclean unless you had any other comments on major portions of this, I think it is ready for review? |
|
Thanks! We'll review this when we can. |
findOrNew, firstOrCreate, createOrUpdate (& related methods) methods to Entry & Term query builders
duncanmcclean
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this pull request!
I've made a couple of tweaks to the tests and implemented a few of the other methods missing from our query builder implementation.
I've also opened #9976 which includes some of the methods useful for all of Statamic's query builders.
Wow thank you for all of these improvements! This will help a ton in our use cases. |
|
Thanks @godismyjudge95 for dedicating your time to this, such a great PR. I'd love to see this merged 🙏🏻 |
|
@duncanmcclean I know this was approved awhile ago, are there any more blockers or things I can do to help the process? If not that is ok, just wanted to check and make sure. |
Nah, it's just waiting on a final review on our side. 👍 |
# Conflicts: # src/Stache/Repositories/EntryRepository.php # tests/Data/Taxonomies/TermQueryBuilderTest.php
findOrNew, firstOrCreate, createOrUpdate (& related methods) methods to Entry & Term query buildersfindOrNew, firstOrCreate, createOrUpdate (& related methods) methods to Entry & Term query builders
findOrNew, firstOrCreate, createOrUpdate (& related methods) methods to Entry & Term query builders|
Sorry to be a buzzkill, but I've removed the query builder methods. I didn't really want to introduce the concept of updating/creating things by "attributes" as they don't really translate well to Statamic objects too often. We don't have a "create" concept either (e.g. Entry::create()). There's often extra steps after newing up the entry/term. There's the extra layer of awkwardness with taxonomies in that you might get a localizedterm. As much as I would love for our query builders to be 1:1 with Eloquent, they are really more just "heavily inspired". I know that means this PR isn't really much anymore. Maybe the meat of it can return at a later date. Thanks for understanding. |
This PR adds a few helper methods to the repositories/facades: firstOrCreate and updateOrCreate.
These methods exist on Laravel eloquent models:
https://laravel.com/docs/11.x/eloquent#retrieving-or-creating-models
https://laravel.com/docs/11.x/eloquent#updates
As a result, this PR attempts to replicate that functionality but for Statamic's content types.
I am marking this as a draft as I would like to implement this for all reasonable facades/repositories.
If I am off track on the implementation feel free to point it out.