I've been learning silverstripe for a little while now but I've come across an issue that I hope someone can help me with. I've created a DataObject (let's call it PaperClip). I want to attach my PaperClip to a Page - sure - I form an extension using PaperClip and decorate SiteTree or Page with it. In my Page I specify "$has_one = array('PaperClip'=>'PaperClip')". Now, how do I specify the reverse relationship in my PaperClip object (Has One Page) without modifying the PaperClip DataObject or PaperClip Extension code?
The goal is to abstract my PaperClip so it can be attached to any object type, a Page, a Memo, an Envelope, a Dog.
Maybe something like: mysite/_config -> PaperClip::$has_one = array('Dog'=>'Dog'); Should I wish to attach my PaperClip to a dog.
Take a look at how Comments (https://github.com/silverstripe/silverstripe-comments/blob/master/code/Commenting.php#L46) or Fulltextsearchable works. Usually you can have an extension that you apply to the page, and in that extension you add the new relationship.
Hey Will, thanks for that pointer. I might adopt your idea of providing a helper class with a module as I wasn't sure were to put a reference to the directory name of the module.
Back to the prob at hand: I'm not really having any trouble with the Parent->Child relationship since that is taken care of inherently when you use DataObject::addExentsion(....); What I'm not sure about is the Child->Parent relationship. Taking your code as an example, I see that you reference the DataObject you have attached Comments to by stating $has_one = array('Parent'=>'DataObject'); - https://github.com/silverstripe/silverstripe-comments/blob/master/code/dataobjects/Comment.php#L21
That's a good solution but what if I (as the coder) have no knowledge of how the end-user wants to use my PaperClip DataObject. They may wish to attach it to a page using many_many, has_one, etc. I'm still left wondering how to change the relationship in my PaperClipExtension (extraStatics method) and my PaperClip Data Object from outside the modules code.