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

many_many not work directly with File #324

Open
2 tasks done
rasstislav opened this issue Feb 19, 2025 · 10 comments
Open
2 tasks done

many_many not work directly with File #324

rasstislav opened this issue Feb 19, 2025 · 10 comments
Labels

Comments

@rasstislav
Copy link

rasstislav commented Feb 19, 2025

Module version(s) affected

4.1.1

Description

The many_many relation does not work directly with File.

How to reproduce

<?php

use SilverStripe\Assets\File;
use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{
    private static $many_many = [
        'Files' => File::class,
    ];
}

Possible Solution

No response

Additional Context

No response

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)

PRs

@GuySartorelli
Copy link
Member

What do you mean by "does not work directly"?
What are you expecting to happen? What does happen instead? Please give details about the problem you're experiencing.

@rasstislav
Copy link
Author

rasstislav commented Feb 20, 2025

2 cases:

  1. with defined relation:

Example

<?php

use SilverStripe\Assets\File;
use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{
    private static $many_many = [
        'Files' => File::class,
    ];

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        if ($files = $fields->dataFieldByName('Files')) {
            ($filesConfig = $files->getConfig())
                ->addComponent(new \Colymba\BulkUpload\BulkUploader('Files', 'MyDataObject'))
            ;
        }

        return $fields;
    }
}

Result

500 - Something went wrong, please try again

ERROR [Emergency]: Uncaught InvalidArgumentException: ManyManyList::add() expecting a SilverStripe\Assets\File object, or ID value IN POST /admin/my-objects/MyDataObject/EditForm/field/MyDataObject/item/1/ItemEditForm/field/Files/bulkupload/upload

  1. without defined relation:

Example

<?php

use SilverStripe\Assets\File;
use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{
    private static $many_many = [
        'Files' => File::class,
    ];

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        if ($files = $fields->dataFieldByName('Files')) {
            ($filesConfig = $files->getConfig())
                ->addComponent(new \Colymba\BulkUpload\BulkUploader())
            ;
        }

        return $fields;
    }
}

Result

Image Image Image

File ID #748 is my uploaded file

File with ID #749 is BUG

In my many_many DB table is linked dummy (BUG) file

@GuySartorelli
Copy link
Member

When does the error occur? Please give detailed step-by-step instructions. Is it just on dev/build? Or when I take some very specific steps in the CMS?

@GuySartorelli
Copy link
Member

Also your second code example says "without defined relations" but there's a many_many relationship defined there

@GuySartorelli
Copy link
Member

Please also provide words along side your image in "results". I can see the image, but I don't understand what it's trying to tell me.

@rasstislav
Copy link
Author

Also your second code example says "without defined relations" but there's a many_many relationship defined there

In constructor: new \Colymba\BulkUpload\BulkUploader('Files', 'MyDataObject')

@rasstislav
Copy link
Author

rasstislav commented Feb 20, 2025

When does the error occur? Please give detailed step-by-step instructions. Is it just on dev/build? Or when I take some very specific steps in the CMS?

when uploading a file

@rasstislav
Copy link
Author

Please also provide words along side your image in "results". I can see the image, but I don't understand what it's trying to tell me.

Done. Sorry. I was preparing a reply, but it sent itself after some keyboard shortcut, but I hadn't finished writing it yet.

@GuySartorelli
Copy link
Member

when uploading a file

Please give detailed step-by-step instructions.

I'm sorry to repeat myself here but the CMS Squad is literally two people. The more details you give, the easier it is to justify spending time looking at this, because it requires less effort and time to look into.

@rasstislav
Copy link
Author

when uploading a file

Please give detailed step-by-step instructions.

I'm sorry to repeat myself here but the CMS Squad is literally two people. The more details you give, the easier it is to justify spending time looking at this, because it requires less effort and time to look into.

Yes, I understand :). For this reason, I am preparing a pull request immediately ;-).

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

No branches or pull requests

2 participants