Jump to content

defect using FieldtypePage in selectors


rajo
 Share

Recommended Posts

I came across this earlier <https://processwire.com/talk/topic/5673-how-to-assign-users-to-page-field/?p=65747> and thanks to Soma I worked around it.  I just came across it in a different context and forgot and spun my wheels.  Unless I'm really misunderstanding, there's a defect in the lack of symmetry between using TypefieldPage in selectors in the $pages->find() vs. PageArray->find() and there should not be.  Plainly, the following code should not behave like it does.  The find() against the PageArray should return the same result but doesn't in the 1st example using name instead of ID.

// a problem with TypefieldPage in selectors
 
$selector = 'tags=plain';
echo "using \$selector : {$selector}\n";
 
$res = wire('pages')->find( $selector );
echo "using \$pages->find : {$res->count()}\n";
 
$res1 = $res->find( $selector );
echo "using pageArray->find : {$res1->count()}\n"; 
 
// versus
 
$tag = wire('pages')->findOne( 'template=tag,name=plain' );
 
$selector = "tags={$tag->id}";
 
echo "using \$selector : {$selector}\n";
 
$res = wire('pages')->find( $selector );
echo "using \$pages->find : {$res->count()}\n";
 
$res1 = $res->find( $selector );
echo "using pageArray->find : {$res1->count()}\n";
 
/*
output:
 
using $selector : tags=plain
using $pages->find : 1
using pageArray->find : 0
using $selector : tags=1343
using $pages->find : 1
using pageArray->find : 1
 
*/
  

 
It's because the find/matches/(filter) methods work differently in Pages than in PageArray.  I don't think this should be so.
 
FYI, in this case, I'm building a form where tags can be assigned as a filter. It works well using tag->name if the filtering is against $pages, but not if it's against the results of $pages->find(), which I need because I need 2 layers of filtering.  On to using tag->id...

Did I mention I freeeekin' loooove pw?  I do I do!

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

×
×
  • Create New...