Jump to:

23017 Posts in 11876 Topics by 2830 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: 655 Views
  • Possibles
    Avatar
    Community Member
    16 Posts

    SortableDataObject problem [SOLVED] Link to this post

    Hello

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

    http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-2-using-model-admin-and-url-segments-to-create-a-product-catalogue/

    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 :
    Photo.php

    <?php

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

    ?>

    Product.php

    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 (
          'Title',
          'URLSegment',
          'Description',
          '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
             array(
                '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
          $Categories = DataObject::get('CategoryPage');
          $f->addFieldToTab("Root.Categories", new CheckboxsetField('Categories', 'Categories', $Categories));
    return $f;

          
       }
    ......

    ProductAdmin

    <?php

    class ProductAdmin extends ModelAdmin {

       public static $managed_models = array(
          'Product'
       );
       
       static $url_segment = 'products';
       static $menu_title = 'Products';
       
    }

    Thanks

  • martimiz
    Avatar
    Forum Moderator
    1038 Posts

    Re: SortableDataObject problem [SOLVED] Link to this post

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

  • Possibles
    Avatar
    Community Member
    16 Posts

    Re: SortableDataObject problem [SOLVED] Link to this post

    That was it !

    I have got to change my brain

    Thanks

    655 Views
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.