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...
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.
DataObjectManager Module /
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
Pagetype inheriting full db?
EDIT: yea sorry totally misunderstood that one :)
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');
I think I understand, so in Page.php I change $this to $this->setParentClass('Page'), or am I way off?
No, you need to run that function on the DataObjectManager
$manager = new DataObjectManager(
...
);
$manager->setParentClass('Page');
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');