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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

GridField - Pre-populate the relationship on the add form

Go to End

4 Posts   953 Views


Community Member, 9 Posts

8 May 2013 at 12:12am

Good morning,

I have a page with a $has_many relationship to VideoSnippets. VideoSnippets class extends from DataObject and includes a $has_one relationship back to my page. It all works fine, but in the CMS when I go to my page, and click the big green button to add a VideoSnippet to the page I am on, the droplist for the page (relationship) is blank. I would expect this to be populated since it knows (shows in the bread crumbs) the page I clicked the Add on.

The droplist for the relationship is blank in the form, and hitting save will select the correct page. However is there a way I can have it already selected, or, even better, don't even show the relationship droplist?


Nobrainer Web

Community Member, 138 Posts

8 May 2013 at 5:38am


You can easily remove the field by adding $fields->removeByName('PageID'); into the getCMSFields function of your DataObject.

I have been wondering why this field get's shown, but i guess it has to do with the fields be generated by the form scaffolidng.
The really weird part is that it will not allow you to actually change the relation to another page, if you try, it just sets the same page again.

Hope it helps


Community Member, 9 Posts

8 May 2013 at 8:12am

Perfect, that worked great thanks!.
I didn't think to do that, as I didn't think that method would exist/be called on the DataObject, I thought it came off page.

It would be even beter, if once it saved it redirected back to the gridview, instead of just reloading the page with green "Saved" message.

That wouldn't be a method on the DataObject, that would be something in the core to fix yea?

Nobrainer Web

Community Member, 138 Posts

8 May 2013 at 6:19pm

There is an extension from UncleCheese that does exactly that (and a bit more)

I have only tried it on 3.1 but works there, however it returns you to the main tab of the page.