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

Listening to ManyMany change events


Reply

4 Posts   187 Views

Avatar
senorgeno

30 July 2014 at 5:59pm Community Member, 10 Posts

Im wanting to create basic versioning of the Group changes for a Member. If someone gets added to a new group either programmatically or via the CMS I would like to version this.

There isn't an extend hook on ManyMany list add so I can't see a way of somehow 'listening' to the add() event on a manymany list. Perhaps subclassing ManyMany and Object::useCustom()?? (seems very hacky) Or should I create a pull request with the extend function included for this? I can see it being handy in many other cases..

Another solution I had was that given Many Many table aren't versionable, creating a Group_Member DO with 2 has many joins coming in form Member and Group and versioning this.

Thoughts, ideas?

Avatar
Fred C.

1 August 2014 at 3:55am Community Member, 18 Posts

Do you need versioning with rollback, or just a journal of changes? The Versioned class is a DataExtension, so you won't be able to apply it to ManyManyList, which does not descend from DataObject. So it seems you'll either have to patch ManyManyList or its ancestors, or write your own Extension subclass.

Avatar
senorgeno

1 August 2014 at 2:14pm Community Member, 10 Posts

I need a journal of changes. My idea of essentially replicating the Group_Member join table into a DataObject was a potential work around for ManyMany relations not being able to be versioned/journaled.

Ideally there would be a $this->extend() hook in ManyMany add(), then I could create an extension to work this in, however I'd prefer not to fork sapphire unless others deemed this reusable/a good idea.

Not sure what the protocol is on a change like this if I am not sure its best practice. Should I do a pull request? Then wait to hear feedback for core team?

Avatar
Willr

5 August 2014 at 9:30pm Forum Moderator, 5511 Posts

Hi senorgeno,

Not sure what the protocol is on a change like this if I am not sure its best practice. Should I do a pull request? Then wait to hear feedback for core team?

In this situation, post to the Google dev group so that a correct course of action can be decided on (either an extension hook or someone finally get's sorted and builds an event system).

https://groups.google.com/forum/#!forum/silverstripe-dev