How to access value of $has_one related page in DataObject?


Silverstripe Version: 4.3.3

This might be really simple, but I just can’t seem to figure out how. What I try to accomplish is to create a page with document groups which are my DataObjects. I want to create folder dynamically for this. The systematic for the folder structure should be Meetings/Category/MeetingPageTitle/DocumentGroupTitle.
I create the Category folder in the MeetingPage when the user has chosen the Category. In the DocumentGroup (Dataobject) I would like to hand down the Category and store this in the DataGroup, so I can access this in the Documents (DataObject), so that I can create the folder structure, so the Documents know in which folder to get stored.

I thought I write the Category in the onBeforeWrite() method, but I don’t know how, as the MeetingPage isn’t a parent in this case. So, I am looking for something like this

public function onBeforeWrite() {
        $this->MeetingCategory = $this->parent()->MeetingCategory;

for the DataObject.

I hope that made sense.

I will than probably need the same method to get the Documents dataobject to know the category?

Or has someone a better idea how to go about this?

Thank you very much.