Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Pagetype inheriting full db?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1049 Views
  • Karai
    Avatar
    Community Member
    13 Posts

    Pagetype inheriting full db? Link to this post

    http://pastebin.com/m6e0cc5ce

    Those are my Page.php and HomePage.php files, cut down to only show the relevant parts. The problem I'm having is on my Home page, it is displaying all of the RelatedLinks from the other pages, and does not have any unique to itself. I can't for the life of me figure out why this is happening...

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Pagetype inheriting full db? Link to this post

    EDIT: yea sorry totally misunderstood that one

  • UncleCheese
    Avatar
    4085 Posts

    Re: Pagetype inheriting full db? Link to this post

    Common problem. You've passed $this as the controller for the DOM, so when it updates your RelatedLink object, by default, it will try to set the foreign key {ControllerPage}ID. When the controller page is a Page object, that works fine (PageID). But when it's a HomePage, or any other subclass of page, that will fail when it tries to set HomePageID on your RelatedLink object.

    Solution:

    ->setParentClass('Page');

  • Karai
    Avatar
    Community Member
    13 Posts

    Re: Pagetype inheriting full db? Link to this post

    I think I understand, so in Page.php I change $this to $this->setParentClass('Page'), or am I way off?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Pagetype inheriting full db? Link to this post

    No, you need to run that function on the DataObjectManager

    $manager = new DataObjectManager(
    ...

    );

    $manager->setParentClass('Page');

  • Karai
    Avatar
    Community Member
    13 Posts

    Re: Pagetype inheriting full db? Link to this post

    Amazing, it works! Thank you!

    //related links tab   
    $fields->addFieldToTab("Root.Content.RelatedLink",
       $manager = new DataObjectManager(
          $this,
          'RelatedLinks',
          'RelatedLink',
          array('Title' => 'Title','Address'=>'Address'),
          'getCMSFields_forPopup'
       )
    );

    $manager->setParentClass('Page');

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