Jump to content

$pages->has() with exclusions, or maybe a findOneID()


adrian
 Share

Recommended Posts

Hi everyone,

Does anyone know if the idea of a $pages->has() that doesn't return unpublished, hidden, trashed pages has been discussed anywhere?

Currently, has() works like get() but I would like to see it work like findOne() - ie one result, but with the exclusion rules in place. I just don't see many uses for has() in its current form. 

Based on these tests, and the fact that has() and getID() have basically the same time execution time, even a findOneID() would work.

image.thumb.png.8b5b48400223ce4b1ff68516cceb3bbd.png

Any info on this would be great, otherwise I'll add it to the Requests GH repo.

  • Like 1
Link to comment
Share on other sites

17 hours ago, adrian said:

Just an observation, thanks to Tracy's Selector Queries (Debug Info panel), both the has() and getID() methods use the same query.

getID() is just an alias of has() - I requested that alias because to my way of thinking it's a clearer name for what the method does.

On 3/7/2021 at 4:21 PM, adrian said:

Currently, has() works like get() but I would like to see it work like findOne()

I think what you're asking for is a new findOneID() method ?.

getID() works just as it should in my opinion - getID() is to get() as findIDs() is to find().

Once upon a time we only had find() and get(), and then findOne() was introduced to save doing find("limit=1")->first(). So it would be cool to have a similar findOneID() labour-saving method, and in the meantime you could use findIDs() with a limit of 1.

  • Like 1
Link to comment
Share on other sites

4 hours ago, Robin S said:

I think what you're asking for is a new findOneID() method ?.

That's what it says in the title of this request: "or maybe a findOneID()" ?

4 hours ago, Robin S said:

getID() works just as it should in my opinion - getID() is to get() as findIDs() is to find().

I completely agree that getID works as it should. I think that perhaps has() is a confusing term given what it does - it's hard to know by its name whether it will work like a get or a find (ie with exclusions or not). But, we also clearly agree on that ?

Request just posted: https://github.com/processwire/processwire-requests/issues/394

  • Like 2
Link to comment
Share on other sites

8 hours ago, adrian said:

That's what it says in the title of this request: "or maybe a findOneID()"

Oh man, I must be going blind - totally overlooked that, sorry. Just went straight to the text and thought you were saying has()/getID() wasn't useful and should be changed.

Thanks for opening the request - thumbs up added ?

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...