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

Versioned DataObjects in Model Admin


Reply

6 Posts   2431 Views

Avatar
Apophenian

3 April 2009 at 4:11pm (Last edited: 3 April 2009 4:11pm), Community Member, 46 Posts

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

7 April 2009 at 8:44pm Community Member, 712 Posts

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

26 April 2009 at 11:00pm Forum Moderator, 801 Posts

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

28 April 2009 at 11:00am Community Member, 712 Posts

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

28 April 2009 at 11:12am Community Member, 46 Posts

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

27 June 2009 at 2:51am Community Member, 509 Posts

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