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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Versioned DataObjects in Model Admin


Go to End


6 Posts   3358 Views

Avatar
Apophenian

Community Member, 46 Posts

3 April 2009 at 4:11pm

Edited: 03/04/2009 4:11pm

I was wondering if it is possible, and if anyone has any advice on how to implement versioned DataObjects in modeladmin?
I have done some testing, and it seems I do find myself with a 'Versions' tab in ModelAdmin, but this appears to be empty, even after I have saved the Object multiple times, and have rows in the *_versions table. Also, it displays an 'Add Site Tree' link at the bottom of the page. I guess I can block this field in the form and define my own, so that's more of a curiosity than an issue, but I was also wondering if you can have versions in related objects ie, in the tables generated by the many_many relationships.

I hope someone can make head or tail of my ramblings!

Thanks,

Rane

Avatar
Hamish

Community Member, 712 Posts

7 April 2009 at 8:44pm

Versioned doesn't seem to be suitable for DataObjects - it is linked too closely with SiteTree to really be suitable for other DataObjects. I believe the problem with ModelAdmin would be that it is not performing the right actions to create a version history. Versioned requires that you you 'publish', instead of just writing.

I've tried a couple of times and always ended up doing something custom based on what I needed.

A generic 'History' extension shouldn't be too hard to make though. Create a decorator, use it to augment the database with an additional 'changes' table per object. Whenever an update is made, intercept the call and copy the object to the history table before updating the object. It doesn't give your the 'multiple stages' functionality of Versioned, but you don't usually need that for DataObjects.

Avatar
Ingo

Forum Moderator, 801 Posts

26 April 2009 at 11:00pm

Hamish, what problems did you have with Versioned on non-SiteTree DataObject subclasses? I've used it a couple of times in the past in these scenarios, worked fine for me.

Of course you have to create your own interfaces for showing versioned historical info (perhaps in a TableListField?), and new ModelAdmin subclassed functionality for rolling back etc. - if you get anywhere, experiences and example code would be appreciated. Ideally we'd get this working out of the box, but we need some use cases first so we don't run off in the wrong direction ;)

Avatar
Hamish

Community Member, 712 Posts

28 April 2009 at 11:00am

Actually, I retract some of what I said. It is more a documentation issue than anything else (although, I hope that I echoed your comment that you need to add the actions to ModelAdmin to handle the versioning).

I'm about to give it another crack, so I'll add to this thread with what I've found.

Avatar
Apophenian

Community Member, 46 Posts

28 April 2009 at 11:12am

Cool, thanks for your replies - I haven't tried any of this yet, as I was just doing some preparation for a project we may or may not be doing.

Avatar
Mo

Community Member, 541 Posts

27 June 2009 at 2:51am

Hey all,

I was just wondering if anyone got any further with this? I find myself in the situation that adding a version history to data objects would be very useful, but an not really sure where the best place to start is.

Cheers,

Mo