Jump to:

23478 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SortableDataObject problem [SOLVED]

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

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

Page: 1
Go to End
Author Topic: 722 Views
  • Possibles
    Community Member
    16 Posts

    SortableDataObject problem [SOLVED] Link to this post


    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/possibles.net/httpdocs/silvertest/sapphire/core/model/MySQLDatabase.php

    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';


  • martimiz
    Forum Moderator
    1086 Posts

    Re: SortableDataObject problem [SOLVED] Link to this post

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

  • Possibles
    Community Member
    16 Posts

    Re: SortableDataObject problem [SOLVED] Link to this post

    That was it !

    I have got to change my brain


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.