Jump to content

has_parent=1 includes 'home'?


theo
 Share

Recommended Posts

Hello

Can anybody explain, why the result of the selector "has_parent=1" includes 'home'?

$homes=$pages->findIDs("has_parent=1");
echo $pages->get($homes[0])->name; //returns 'home'

I would expect that 'home' is not a parent of itself.

Thank you.

Link to comment
Share on other sites

No idea - just the observation that the result is the same when you use $pages->find() with the $options parameter like this:

$options = array('findIDs'=>1);
$homes=$pages->find("has_parent=1", $options);
echo $pages->get($homes[0])->name; //returns 'home'
  • Like 1
Link to comment
Share on other sites

Not sure as well, but maybe has something to do with '/' being the only saved page with a NullPage as a parent?

echo print_r($pages->get('/'));

// result 
// ProcessWire\NullPage Object ( ... )

And in the database, home's parent_id is 0, and it does not have an entry in pages_parents. Upon further digging, I also found that home is the only result when querying for "has_parent!=1", and it is hard-coded. 

Anyway, if you require home to not be in the result, maybe just exclude it from the query?

$childrenOfHome = $pages->find("has_parent=1, id!=1");

 

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

@alxndre Sure it is not really a problem, once you know how it works.

For my case this does what I want:

$pages->find("id!=1,has_parent!=2");

Meaning: all, except home and everything under admin (For logged in admins).

But still, such little uncertainties can diminish confidence in the system.

Link to comment
Share on other sites

29 minutes ago, Zeka said:

@theo

I think that is something that should be reported. 

Could you open an issue on Github, so Ryan could comment is it intended behavior or a bug? 

This has always been the case as far as I can remember. Similar to rootParent of home:

$h = $pages->get(1);
echo $h->rootParent->id;// outputs 1

You'd think home shouldn't have a root parent, but it does. I think both were intended, but let's see what @ryan says.

Edited by kongondo
  • 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...