Jump to:

3428 Posts in 1056 Topics by 733 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Dataobject association

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

Page: 1
Go to End
Author Topic: 1201 Views
  • Mo
    Avatar
    Community Member
    504 Posts

    Dataobject association Link to this post

    Hi all,

    Quick question. I have a page that is listing out all iterations of a data object. Each iteration is associated with one of the page's children.

    How would I retrieve the child page association from the parent?

    IE:
    Child->Title
    Child->Content

    Currently I am using this (very simple) method and iterating through the results in the template file:

    public function GalleryList() {
       $GalleryList = DataObject::get('ObjectPeekImage');
       return $GalleryList;
    }

    Any help in this would be appreciated.

    Mo

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Dataobject association Link to this post

    That's a little confusing. Are you trying to figure out if the page related to ObjectPeekImage is also related to the current page? Or, just get the page related to ObjectPeekImage? Although you say it is related to "the page's children" - so surely you already know the relationship?

    Put it this way, if ObjectPeekImage has a has_one relationship with a page (say "MyPage"), surely you can just do:

    <% control GalleryList %>
       <% control MyPage %>
          <h2>$Title</h2>
          <div>$Content</div>
       <% end_control %>
    <% end_control %>

  • Mo
    Avatar
    Community Member
    504 Posts

    Re: Dataobject association Link to this post

    That is EXACTLY what I was after, thank you soooooo much .

    Mo

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