Skip to content
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

Add find method to query builder #2630

Merged

Conversation

piljac1
Copy link
Contributor

@piljac1 piljac1 commented Oct 10, 2020

This pull request adds a find method to the Statamic\Query\Builder class.

The method takes an ID as the first parameter and an optional array of columns as a second parameter (this array is passed to the get method to set selectedQueryColumns ). It returns the first entry matching the ID (there should only be one of course).

Usage:

Entry::query()->find('the-searched-id');

// or a more "verbose" and exhaustive alternative

Collection::find('posts')->queryEntries()->find('the-searched-id');

I didn't add PHPDoc comment blocks or comments because there weren't any. Same goes for type hinting. If that's an issue, I can adjust as needed.

@jasonvarga jasonvarga merged commit 811e594 into statamic:master Oct 12, 2020
@jasonvarga
Copy link
Member

Thanks!

@AntiCZ
Copy link

AntiCZ commented Oct 14, 2020

Hi, I do not understand why are you doing this.
The method find() is already in a Repository and does the same.

Do not understand the existence of these aliases in the Repository(find, findBySlug, etc.).
I can get QueryBuilder from Repository.

You should do interfaces for QueryBuilder classes then add more unnecessary methods.

@piljac1
Copy link
Contributor Author

piljac1 commented Oct 14, 2020

@AntiCZ

  1. They're not the exact same if you look at the source code, but I agree they should probably be.
  2. There's not always one good way to achieve something. If I can use Laravel as an example, they offer the find method on both the Eloquent builder and the Query builder, when in fact, you can achieve the same result using either one.
  3. I might have missed something, but what do interfaces have to do with this? What do you suggest?

@AntiCZ
Copy link

AntiCZ commented Oct 15, 2020

I have my own Repository and QueryBuilder and saving Entries and Collections to the database. This feature should not be released as a patch(3.0.x) because it is breaking change. There is no interface for QueryBuilder so no errors are raised until someone will call it.

As a developer, I should check every changelog. This is ok. But now have to check very carefully every patch (patches should be saved)

Please make interfaces for QueryBuilder(with typos and comments) and fix interfaces for Repository. Fix I mean add typos and comments. Eg., public function query(); from Statamic\Contracts\Entries\EntryRepository. I don't know what should I do. Do I have to return anything? If yes, what? etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants