Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » DataObjectGet Pagees by parent ClassName

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

Page: 1
Go to End
Author Topic: 888 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    DataObjectGet Pagees by parent ClassName Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: DataObjectGet Pagees by parent ClassName Link to this post

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

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: DataObjectGet Pagees by parent ClassName Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: DataObjectGet Pagees by parent ClassName Link to this post

    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.

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: DataObjectGet Pagees by parent ClassName Link to this post

    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.

    888 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.