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

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

Open
2 tasks done
MatMorrisParker opened this issue Apr 7, 2024 · 1 comment
Open
2 tasks done

Comments

@MatMorrisParker
Copy link

MatMorrisParker commented Apr 7, 2024

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

  • SaleableProduct
  • ProductAttribute

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

  • 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)
@GuySartorelli GuySartorelli changed the title many_many_extraFields causing "ClassName" unknown field error Duplicate field in many_many_extraFields causing "ClassName" unknown field error Apr 7, 2024
@lekoala
Copy link
Contributor

lekoala commented Apr 10, 2024

i think this is a duplicate of this
#10737

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

No branches or pull requests

3 participants