Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » accessing grandparent

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

Page: 1
Go to End
Author Topic: 1232 Views
  • bennettpr
    Avatar
    Community Member
    37 Posts

    accessing grandparent Link to this post

    Hi all,

    I have some parent and grandparent checking to do.

    Parent checking is as so (in Page model):

    function getParent(){
          return ($this->Parent())? $this->Parent()->Title : false;
    }

    This works fine.

    Grandparent checking is as so (in page model)

    function getGrandparent(){
          if($this->Parent()->Parent()){
             return $this->Parent()->Parent()->Title;
          }
          else{
             return false;
          }
    }

    Grandparent checking fails with the following error:

    "Call to a member function Children() on a non-object "

    Now, the class tree should be:
    BookHolder -> BookList -> BookPage

    I've set up BookList to have BookHolder as a parent, so a call from a bookpage, which sits in a booklist (which belongs to a bookholder) should return the title of the BookHolder page?

    Or am I missing something?

    Happy to clarify more if required,
    Paul

    1232 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.