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.

Data Model Questions /

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

Extending page versioning to data objects

Go to End

3 Posts   2005 Views

Tom B.

Community Member, 5 Posts

9 June 2010 at 12:17am

Hi, on our site's HomePage we have a custom DataObject called a "HomePageTab" which is just a little container with 3 news items in it. The problem is that editing these tabs in a draft will alter the tab on the published page as well. Our editors want to be able to see how the tabs look in a draft before publishing them.

I've tried adding this to HomePageTab but it didn't seem to help:

static $extensions = array(
    "Versioned('Stage', 'Live')"

I've also tried moving HomePage's "has_many HomePageTab" into "has_one HomePageTab" but that just breaks the page.

I'm probably missing something incredibly obvious here, so apologies. It's my first post :o]

Here are the relevant bits of HomePage and HomePageTab (I think):

class HomePage extends Page {

    static $allowed_children = array(

    static $has_one = array(

    static $has_many = array(
        'Tabs' => 'HomePageTab',
        'TagCloud'         => 'Tag',
        'PopularDocuments' => 'PopularDocument',

class HomePageTab extends DataObject {
    static $db = array(
        'Title'                 => 'Varchar',
        'ColumnOneText'         => 'Varchar(255)',
        'ColumnTwoText'         => 'Varchar(255)',
        'ColumnThreeText'       => 'Varchar(255)',
        'ColumnOneLink'         => 'Varchar(255)',
        'ColumnTwoLink'         => 'Varchar(255)',
        'ColumnThreeLink'       => 'Varchar(255)',
        'ColumnOneLinkTarget'   => "Enum('_parent, _blank','_parent')",
        'ColumnTwoLinkTarget'   => "Enum('_parent, _blank','_parent')",
        'ColumnThreeLinkTarget' => "Enum('_parent, _blank','_parent')",
    static $has_one = array(
        'HomePage'         => 'HomePage',
        'ColumnOneImage'   => 'Image',
        'ColumnTwoImage'   => 'Image',
        'ColumnThreeImage' => 'Image',


Community Member, 78 Posts

9 June 2010 at 11:01pm

Hi. I don't think you're missing anything obvious. It's versioning, it's not obvious :-)

You're right that you need to apply the Versioned decorator to HomePageTab, but you'll need to do more than that. There is a logical relationship between the HomePage versions and HomePageTab versions. Each HomePageTab version relates to a HomePage version. When a HomePage is published, you'll need to trigger publishing of the HomePageTab objects associated with it at the same time.

You can define an onAfterPublish() function on HomePage which selects the HomePageTab objects associated with the current HomePage object, and publishes them if they are not already published. I hope that makes sense. You need to be careful about which versions of HomePageTab you're dealing with - you want to select draft objects in the onAfterPublish, and publish them. On the front end, be sure that live versions are being selected (you can verify this by adding ?showqueries=1 to the URL, and examining the SQL statements being issued)

Hope this helps.


Tom B.

Community Member, 5 Posts

9 June 2010 at 11:06pm

Thank you so much! I'll have a go at this later. :)