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 ss 3.6 GridFieldAddNewMultiClass Column 'SortOrder' in field list is ambiguous #114

Closed
nimeso opened this issue Dec 6, 2017 · 4 comments

Comments

@nimeso
Copy link

nimeso commented Dec 6, 2017

I'm getting this error 'Column 'SortOrder' in field list is ambiguous'

Parent

<?php
class Quest extends DataObject{

	private static $db = array(
		"Title"            => "Varchar(256)"
                "SortOrder"   => "Int"
	);
	
	static $default_sort = "SortOrder ASC";

	private static $many_many = array(
		"Tasks"      => "Task"
	);

	private static $many_many_extraFields = array(
		'Tasks' => array(
			'SortOrder' => 'Int',
		)
	);

	public function Tasks()
	{
		return $this->getManyManyComponents('Tasks')->sort('SortOrder');
	}

	public function getCMSFields(){

		$fields = parent::getCMSFields();

		$gridfieldPages = new GridField("Tasks","Tasks",$this->Tasks());
		$gridfieldPages->getConfig()
		     ->addComponent(new GridFieldSortableHeader())
		     ->addComponent(new GridFieldSortableRows("SortOrder"))
		     ->addComponent(new GridFieldDetailForm())
		     ->addComponent(new GridFieldEditButton())
		     ->addComponent(new GridFieldDeleteAction())
		     ->addComponent($multiClassPages = new GridFieldAddNewMultiClass());
		$multiClassPages->setClasses( array("TaskText","TaskArea","TaskUpload", "TaskImageUpload", "TaskCode", "TaskLink") );
		$fields->addFieldToTab("Root.Tasks", $gridfieldPages);
		return $fields;
	}

}

Child base class

<?php
class Task extends DataObject{
	
	private static $db = array(
		"Title" => "Varchar(256)"
	);

	private static $belongs_many_many= array(
		"Quests" => "Quest"
	);

	public function getCMSFields(){
		return $fields;
	}
	
}
@UndefinedOffset
Copy link
Owner

I was expecting that actually, either drop the column on the task table or use a different name in the many many extra fields :)

@nimeso
Copy link
Author

nimeso commented Dec 6, 2017

Thanks heaps @UndefinedOffset sorry, I'm not quite following :( Thanks for all your help. could you explain a bit more or send me my code with the corrections?

@UndefinedOffset
Copy link
Owner

Your code is ok, the problem is the Task object (and it's database table) has a field called SortOrder, and your many many extra fields does as well. So when the queries try to run it sees two fields in the database. ao you need to resolve the conflict by either changing the name of your sort column in the many many extra fields to something unique or remove the field from the task class and database table if it's not needed. Either solution should resolve the ambitious column name issue. If I remember right it's a limitation of the orm in silverstripe 3.x where it won't prefix fields with their table name in some scenarios.

@nimeso
Copy link
Author

nimeso commented Dec 6, 2017

Sorted! (see the pun there) thanks.

@nimeso nimeso closed this as completed Dec 6, 2017
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

2 participants