Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SortableDataObject problem [SOLVED]

Go to End

3 Posts   1009 Views


Community Member, 16 Posts

23 November 2011 at 6:36am


I tried to modify Aram's great tutorial about dataobject as pages to be able to add many pictures, I kind of succeeded

I have now another problem I wanted to be able to sort (via drag and drop) the photos. I tried :

SortableDataObject::add_sortable_classes((Photo')); in _config.php

but I get error :
Error: "Couldn't run query: SELECT "Photo"."ClassName", "Photo"."Created", "Photo"."LastEdited", "Photo"."Name", "Photo"."Description", "Photo"."SortOrder", "Photo"."AttachmentID", "Photo"."ProductID", "Photo"."ID", CASE WHEN "Photo"."ClassName" IS NOT NULL THEN "Photo"."ClassName" ELSE 'Photo' END AS "RecordClassName" FROM "Photo" ORDER BY "SortOrder" ASC LIMIT 10 OFFSET 0 Unknown column 'Photo.SortOrder' in 'field list'" at line 525 of /var/www/vhosts/

Here are the codes :


class Photo extends DataObject {

   static $db = array(
	    'Name' => 'Text',
		'Description' => 'Text',
   static $has_one = array(
      'Attachment' => 'Image',
      'Product' => 'Product'
   public function getCMSFields_forPopup()
		return new FieldSet(
			new TextField('Name'),
			new TextareaField('Description'),
			new FileIFrameField('Attachment')



class Product extends DataObject
	static $db = array(
		'Title' => 'Varchar(255)',
		'Description' => 'HTMLText',
		'Price' => 'Decimal(6,2)',
		'URLSegment' => 'Varchar(255)',
		'MetaTitle' => 'Varchar(255)'

	//Set our defaults
	static $defaults = array(	
		'Title' => 'New Product',
		'URLSegment' => 'new-product'
	static $has_many = array(
		'Photos' => 'Photo'
	//Relate to the category pages
	static $belongs_many_many = array(
		'Categories' => 'CategoryPage'
	//Fields to show in ModelAdmin table
	static $summary_fields = array(
		'Title' => 'Title',
		'URLSegment' => 'URLSegment',
		'Price' => 'Price (&pound;)'

	//Add an SQL index for the URLSegment
	static $indexes = array(
		"URLSegment" => true

	//Fields to search in ModelAdmin
	static $searchable_fields = array (
		'Categories.ID' => array(
			'title' => 'Category'

	public function getCMSFields()
		$f = parent::getCMSFields();
		$manager = new FileDataObjectManager(
			$this, // Controller
			'Photos', // Source name
			'Photo', // Source class
			'Attachment', // File name on DataObject
				'Title' => 'Title', 
				'Producers' => 'Producers',
				'URLSegment' => 'URL Segment', 
				'MetaTitle' => 'Meta Title',
				'YearOfFabrication' => 'YearOfFabrication', 
				'Price' => 'Price',
				'Description' => 'Description' 
			), // Headings 
			'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
			// Filter clause
			// Sort clause
			// Join clause
		$f->addFieldToTab("Root.Photos", $manager);
		$Categories = DataObject::get('CategoryPage');
		$f->addFieldToTab("Root.Categories", new CheckboxsetField('Categories', 'Categories', $Categories));
        return $f;




class ProductAdmin extends ModelAdmin {
	public static $managed_models = array( 
	static $url_segment = 'products';
	static $menu_title = 'Products';



Forum Moderator, 1203 Posts

23 November 2011 at 7:34am

Did you do a /dev/build/?flush=1 to update the database?


Community Member, 16 Posts

23 November 2011 at 11:52pm

That was it !

I have got to change my brain