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.

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.

General Questions /

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

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

DataObjectGet Pagees by parent ClassName


Go to End


5 Posts   2302 Views

Avatar
micahsheets

Community Member, 165 Posts

30 August 2011 at 7:09am

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

Avatar
Willr

Forum Moderator, 5523 Posts

30 August 2011 at 2:58pm

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

Avatar
moloko_man

Community Member, 72 Posts

30 August 2011 at 3:56pm

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?

Avatar
Willr

Forum Moderator, 5523 Posts

30 August 2011 at 4:42pm

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.

Avatar
moloko_man

Community Member, 72 Posts

30 August 2011 at 4:50pm

Edited: 30/08/2011 4:54pm

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.