silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
719 stars 820 forks source link

Duplicate field in `many_many_extraFields` causing "ClassName" unknown field error #11190

Open MatMorrisParker opened 2 months ago

MatMorrisParker commented 2 months ago

Module version(s) affected

4.11.15

Description

Posting as requested on Slack.

This issue is being raised to update the error message to make it clearer, not necessarily to fix the issue (which, from past tickets, I understand to be a bit of an undertaking).

My set up included 2 DOs

All of these use SortableGridField and have a "sort" field of some kind, either in the DO or as a many_many_extraField with other DOs.

I kept receiving the error message of Unknown column 'SaleableProduct.ClassName' in 'field list', which is a field pre-populated by SS, but it turned out that having the same field name in the DO and in the many_many_extraFields caused this error.

_In other words, if you have a field with the same name both in the db configuration and the many_many_extraFields configuration, an error is generated which incorrectly points at the "ClassName" field._

I'd like to propose a better error warning on this to help other users identify this issue more quickly. I believe this issue is still present in v5.

For reference: https://silverstripe-users.slack.com/archives/C0QSDASKT/p1558424152053800?thread_ts=1558407507.048800&cid=C0QSDASKT

Similar issues reporting the same error: #2269 #9684

How to reproduce

Written from memory

class SaleableProduct extends DataObject
{
    private static $db  = [
        'Title'             => 'Varchar(255)'
    ];

    private static $has_many = [
        'Attributes'    => ProductAttribute::class
    ];

        private static $many_many_extraFields = [
        'Attributes'    => [
            'SortOrder'         => 'Int'
        ]
    ];
}

class ProductAttribute extends DataObject
{
    private static $db  = [
        'Title'             => 'Varchar(255)',
        'SortOrder'         => 'Int'
    ];

    private static $belongs_many_many   = [
        'Products'      => Product::class
    ];
}

Possible Solution

No response

Additional Context

No response

Validations

lekoala commented 2 months ago

i think this is a duplicate of this https://github.com/silverstripe/silverstripe-framework/issues/10737