Skip to content
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

Getting Descendant of Ancestor with Descendant in a single query #221

Open
soundar8562 opened this issue Nov 23, 2019 · 1 comment
Open
Labels

Comments

@soundar8562
Copy link

soundar8562 commented Nov 23, 2019

Hello,
Here you can see my ancestor and descendant table,
Ancestor | Descendant
Electronics | Computer
Electronics | Laptop
Electronics | Mobile phone

Here is my code,
$page = Page::find(1);
$descendants = $page->getDescendants();
$descendants = $page->getDescendantsWhere('real_depth', '=', 1);
foreach ($descendants as $value) {
$ancestor=$page->getAncestors();
echo $ancestor[0]->name
echo $value->name;
}
}

Question:
As of right now, this works fine, but there will be a lot of queries if I handle some large amount of data, so is there any way to get the descendant of the ancestor with a descendant from a single query?

Thanks

@soundar8562
Copy link
Author

Anyone here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants