Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First-level many-many doesn't create snapshots #23

Open
unclecheese opened this issue Oct 2, 2019 · 1 comment
Open

First-level many-many doesn't create snapshots #23

unclecheese opened this issue Oct 2, 2019 · 1 comment

Comments

@unclecheese
Copy link

unclecheese commented Oct 2, 2019

Steps to reproduce

class MyPhotoPage extends Page
{
    private static $many_many = [
        'Photos' => [
            'from' => 'MyPhotoPage',
            'to' => 'Image',
            'through' => MyPhotoPageImageLink::class,
        ],
    ];

    private static $owns = [
        'Photos',
    ];
}
class MyPhotoPageImageLink extends DataObject
{
    private static $extensions = [
        Versioned::class,
    ];

    private static $owns = [
        'Image',
    ];

    private static $has_one = [
        'MyPhotoPage' => MyPhotoPage::class,
        'Image' => Image::class,
    ];
}
  • Add images
  • Save draft
  • Observe that no "images added" snapshots have been created

Cause

There are two orphaned snapshots that are created here:

  • A snapshot that was created for the image on upload (no ownership at write time)
  • A snapshot that was created when the page was saved and the link was created (MyPhotoPageImageLink created). This should be populated.

The latter snapshot is empty due to this line:

https://github.com/silverstripe/silverstripe-versioned-snapshots/blob/master/src/SnapshotPublishable.php#L645

where linking objects go up the ownership chain of their parents, no the child ,which now has a populated ownership chain. The way this is written, it just tries to create a snapshot for MyPhotoPage, which is empty as it is the top of the chain.

I'm sure it was written this way for a reason -- probably for objects one level deeper?

But either way, this is a really common use case and it's broken.

@kinglozzer
Copy link
Member

I have a simple document -> tags many-many-through: https://gist.github.com/kinglozzer/03ced85925047a094f7bcd0633634cf6

If I create a document like:

Title: tagged foo
Tags: foo

Then update it to:

Title: tagged foo and bar
Tags: foo, bar

When I revert back to the first published version, the title is reverted but the bar tag isn’t removed. Is this issue why that doesn’t happen? Just wanted to check before I open an issue 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants