Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Versioned DataObjects in Model Admin

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

Page: 1
Go to End
Author Topic: 2415 Views
  • Apophenian
    Avatar
    Community Member
    46 Posts

    Versioned DataObjects in Model Admin Link to this post

    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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Versioned DataObjects in Model Admin Link to this post

    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.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Versioned DataObjects in Model Admin Link to this post

    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 ;)

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Versioned DataObjects in Model Admin Link to this post

    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.

  • Apophenian
    Avatar
    Community Member
    46 Posts

    Re: Versioned DataObjects in Model Admin Link to this post

    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.

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Versioned DataObjects in Model Admin Link to this post

    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

    2415 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.