Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

DataObjectGet Pagees by parent ClassName


5 Posts   903 Views


30 August 2011 at 7:09am Community Member, 164 Posts

How do I write a Join clause in DataObjectGet that will return all the pages that have a particular page type as the parent?


30 August 2011 at 2:58pm Forum Moderator, 5511 Posts

SS automatically joins all the parent classes. What happens when you do DataObject::get('ParentClass') ? I think you'll get all the children objects.


30 August 2011 at 3:56pm Community Member, 72 Posts

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?


30 August 2011 at 4:42pm Forum Moderator, 5511 Posts

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.


30 August 2011 at 4:50pm (Last edited: 30 August 2011 4:54pm), Community Member, 72 Posts

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.