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
Unable to find root from node in TreeBehavior #12539
Comments
In order to find root node I used the following
Where $id is the id of the child node. And $root[0]['id'] gives the id of the root. |
This already exists in the form of the From the book $nodeId = 5;
$crumbs = $categories->find('path', ['for' => $nodeId]); |
Thanks @dakota |
if you need to parent of a node ( direct parent ) $categories->find()->where(['id'=>$childNode->parent_id]); but for tree of a node as @dakota said $nodeId = 5;
$crumbs = $categories->find('path', ['for' => $nodeId]); can you explain more , what are you expecting ? |
Hi @saeideng Above is a sample from my database. As you can see, all the comments are from the same flaunts. ID: 1855 is the main comment on the flaunt whereas ID: 1856 is the reply to the main comment(1855) and ID: 1857 is the reply to comment(1856). These table have the TREE behavior creating left tree and right tree. What I expect is if I Get the child node ID: 1862, I can directly get the root node ID: 1855. Right now I am using: |
I think your last code is what you are expecting , true ? $crumbs = $this->FlauntsComments->find('path', ['for' => $childNode])->first(); can we close this issue now ? |
also cakephp/src/ORM/Behavior/TreeBehavior.php Lines 392 to 396 in fc95e24
is like to your code in above 'conditions' => array(
'FlauntsComments.lft <=' => $childNode['lft'],
'FlauntsComments.rght >=' => $childNode['rght']
) and I think |
This is a (multiple allowed):
bug
[x ] enhancement
feature-discussion (RFC)
CakePHP Version: 3.4.
Platform and Target: Xampp with MySQL
What you did
I tried to find the root of the TREE when a child node is given.
What happened
I didn't find any function supporting this feature.
What you expected to happen
As CakePHP have many function to find out list of children from the parent node(ROOT). I was expecting to get the ROOT when children node was provided.
There could be function to extract the path to the node with query like:
SELECT title FROM tree WHERE lft < 4 AND rgt > 5 ORDER BY lft ASC;
and the return the root from it when child node is provided.
P.S. Remember, an issue is not the place to ask questions. You can use Stack Overflow
for that or join the #cakephp channel on irc.freenode.net, where we will be more
than happy to help answer your questions.
Before you open an issue, please check if a similar issue already exists or has been closed before.
The text was updated successfully, but these errors were encountered: