Jump to content

No "path"-select in find() or get()?


David Karich
 Share

Recommended Posts

Is that right, i can't select the path as an OR-option in find() or get()? For example: 

$_pages = wire('pages')->find('id|path=1001|/about/');

produce following error: 

Error: 	Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pages.path' in 'where clause' (in C:\wamp\www\Development\Processwire-Modules\PW-TESTING\wire\core\DatabaseQuery.php line 86)

Same with ->get();

PHP: 5.3 and 5.5, PW version: 2.4

Link to comment
Share on other sites

To be honest I haven't actually used that module until now. I am also having issues with the selectors you are trying, but the following all work fine:

path=/about/

id=1,path=/ 

path%=/about/

I think it is logical that %= wouldn't be supported for id, although I can see the issue when you're trying to combine OR's like that.

Not sure if that really helps, but I am sure Ryan or someone else more familiar with that module will chime in soon.

  • Like 1
Link to comment
Share on other sites

I thought that too, but then I noticed that:

id|name=1|about

returns Home and About

and:

id|name=1001|about 

returns just About.

Is it possible that Ryan has introduced partial/unannounced support already, or am I missing the point?

Link to comment
Share on other sites

@adrian: http://processwire.com/talk/topic/2942-or-in-pw-selectors/?p=29001

On a mobile so I'll be very brief, but just wanted to add that the original issue is exactly what error message says: id field and %= can't be used together. You could use a combination of two finds (fetch two PageArrays and merge them) to achieve this, though someone might know better way too..

  • Like 1
Link to comment
Share on other sites

Thanks for the link teppo, but none of the examples that David or myself have posted here are of the either/or ilk.

Just to spell it out,

id|name=1|about

would be the same as:

WHERE id=1 OR name=1 OR id=about OR name=about 

An either/or would maybe be:

WHERE (id=1 AND name=home) OR (name=about) 

It's late here, so maybe I am not thinking straight, but I think I am on the right track?

That said, I am not exactly sure what David is wanting to achieve with the a|b=c|d style selector. Maybe he is after an either/or, even though that's not what it currently does. I actually don't think I've seen this style documented anywhere either, but maybe it is just assumed to be obvious based on what else you can do. I might sign off now before I confuse anyone else :)

Link to comment
Share on other sites

You are right Adrian, I was the one confusing this :)

Teppo is right too, error comes with using %= with id. It doesn't make any sense to use %= with id, since id%=1000 would match id:s like 910003 etc.. (if those would be strings).

Link to comment
Share on other sites

@adrian, you're on the right track there, but the point is that you can't use '%=' with id's and '=' isn't always enough for text-searches, so in order to include both queries in one selector and achieve what (I believe that) David was trying to achieve you'd have to use an either-or selector (see examples below) or combine results of two separate queries.

// wrong
id|name%=1001|about

// correct, but *not* the same thing
id=1001, name%=about

// correct, but requires either-or selector
(id=1001)||(name%=about)

// probably correct, but requires either-or selector and makes very little sense
(id=1001|about)||(name%=1001|about)

Forgive me for using dummy syntax for either-or, I've no idea how Ryan is going to implement this :)

It should also be noted that id|name%=1001|about, if it worked (or that last either-or example above), would also return pages with names like "mypage1001", which probably wasn't intended. Considering that, this is definitely a job for either-or selector (first one in example above) or two combined queries.

Link to comment
Share on other sites

I think it is logical that %= wouldn't be supported for id, although I can see the issue when you're trying to combine OR's like that.

On a mobile so I'll be very brief, but just wanted to add that the original issue is exactly what error message says: id field and %= can't be used together. 

Teppo is right too, error comes with using %= with id. It doesn't make any sense to use %= with id, since id%=1000 would match id:s like 910003 etc.. (if those would be strings).

@adrian, you're on the right track there, but the point is that you can't use '%=' with id's and '=' isn't always enough for text-searches, so in order to include both queries in one selector and achieve what (I believe that) David was trying to achieve you'd have to use an either-or selector (see examples below) or combine results of two separate queries.

It should also be noted that id|name%=1001|about, if it worked (or that last either-or example above), would also return pages with names like "mypage1001", which probably wasn't intended. Considering that, this is definitely a job for either-or selector (first one in example above) or two combined queries.

I think we were at least all on the same track regarding the issue with id and %= :)

On the either / or issue - I really can't wait for this, it is one of the very few things in PW that are sometimes a cause of frustration because it not only feels dirty combining more than one page array, but also because of the issues regarding pagination when you do end up doing that.

Nice examples there teppo :)

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...