How do I write a Join clause in DataObjectGet that will return all the pages that have a particular page type as the parent?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
SS automatically joins all the parent classes. What happens when you do DataObject::get('ParentClass') ? I think you'll get all the children objects.
Is there a way to do this on a DataObject instead of a Page?
for example I have:
Category has_many SubCategory (SubCategory has_one Category)
SubCategory has_many Item (Item has_one SubCategory)
Then retrieve the parent or grandparent of Item?
Well thats slightly different to your earlier question.
If you have the given item, you can use the ORM to get that (it won't be lighting quick). $item->Subcategory()->Category();
If you're trying to get it via DataObject::get() then you have to write a standard SQL JOIN cause to join subcategory and category.
Sorry, I kind of hijacked this post there. My question was different from the OP.
Thank you for that quick response @Willr
Apologies @micahsheets. I've sort of done what you are asking, but I've never put it with join before.
WIllr's answer is correct, I've tested it and it returns a list of children belonging to the called class.
EDIT: WIllr, using $this->SubCategory()->Category() works perfectly! Love how simple it was. Thanks again.