Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DataObject with link to page

Go to End

2 Posts   1206 Views


Community Member, 39 Posts

16 July 2010 at 12:02am

Edited: 16/07/2010 12:04am

I'm stuck at the following:

class MyLink extends DataObject {

public static $db = array(
"Title" => "Varchar(255)",

public static $has_one = array(
"ParentPage" => "SiteTree",
"PagePointer" => "SiteTree",

function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push(new TextField('Title','Link title'));
$fields->push(new SimpleTreeDropdownField('PagePointerID','Select page'));
return $fields;

and on MyErrorPage :

class MyErrorPage extends ErrorPage {

public static $has_many = array(
"LinkList" => "MyLink",

function getCMSFields() {
$fields = parent::getCMSFields();

$manager = new DataObjectManager(
"Title" => "Title",

return $fields;


When I comment out 'PagePointer' and SimpleTreeDropdownField from 'MyLink' class, everything works perfect. I can add MyLink items in DOM and then list them in a control (at MyErrorPage):

<% control LinkList %>
<% end_control %>

But after adding this:

"PagePointer" => "SiteTree",

and this:

$fields->push(new SimpleTreeDropdownField('PagePointerID','Select page'));

and rebuilding the database, LinkList control stops working. It doesn't matter if I set the value of PagePointerID or not, <% control LinkList %> is just empty, not a single item being shown.

I triple checked everything, what am I missing here?


Forum Moderator, 4102 Posts

16 July 2010 at 2:24am

Your $has_many relationship is not reciprocated with a $has_one. Link needs to have a $has_one MyErrorPage (or wherever the DOM is). That's the data relationship that counts. $has_many just creates the template function.