Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Unable to have an Abstract Data Object #2856

oilee80 opened this Issue · 1 comment

4 participants


Due to how the DataObject inheritance works it is not possible to have an abstract DataObject. The use case for this would be:

abstract class MediaLinkRelationship extends DataObject {
    private static $db = array('Title' => 'Varchar','AltName' => 'Varchar',.....);
    private static $has_one = array('MediaItem' => 'MediaItem');
class PageMediaLinkRelationship extends MediaLinkRelationship {
    private static $has_one = array('Parent' => 'Page');
class AnotherDataObjectMediaLinkRelationship extends MediaLinkRelationship {
    private static $has_one = array('Parent' => 'AnotherDataObject');

The error occurs during build as it is trying to instantiate the abstract class (MediaItemRelationship) during DatabaseAdmin::doBuild().


The problem is that user Extensions rely on instances, and the 'augmentDatabase' extension hook needs to be available to each discrete class at the point of DB generation. Not allowing DataObject classes to be abstract is one of the concessions that was made in favour of this functionality.

For the sake of pages, if you don't want a base class to be directly instantiated in the CMS you can at least use the hide_ancestor config. Other than this, what reason do you need abstract DataObject classes for? Is your problem not one that could be solved (for instance) using interfaces?

@simonwelsh simonwelsh added the 3.1 label
@wilr wilr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.