Jump to:

7913 Posts in 1355 Topics by 930 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Bug Reports

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
Go to End
Author Topic: 37846 Views
  • Nimblor
    Avatar
    Community Member
    1 Post

    Re: Bug Reports Link to this post

    Found an issue with ManyManyDataObjectManager - when working with objects that have no sortable properties, and no default sort behaviour defined, the popup window fails to open (shows a query error)

    The query error is due to DataObjectManager adding an ORDER BY clause to the query, when it has no field to sort by. Because the 'sort' value is coming from $_REQUEST, even though it was NULL on the server, its received as an empty string, and so checking for a sort condition with isset() returns true.

    The fix seems quite simple, change line 104 of ManyManyDataObjectManager.php from:

    elseif(isset($_REQUEST['ctf'][$this->Name()]['sort'])){


    To:

    elseif(!empty($_REQUEST['ctf'][$this->Name()]['sort'])){

    The same issue may occur with the other types (ie HasManyDataObjectManager), I haven't looked into them since we aren't using them for anything ;)

  • MarijnKampf
    Avatar
    Community Member
    150 Posts

    Re: Bug Reports Link to this post

    I'm trying to use a variable that has many Images for a page banner using the code below:

    BannerFile.php:

    class BannerFile extends Image {

       static $has_one = array (
          'Pages' => 'Page'
       );

    }

    Page.php

       public static $has_many = array(
          'BannerFiles' => 'BannerFile'
       );

       function getCMSFields() {
          $fields = parent::getCMSFields();

    $fields->addFieldToTab("Root.Content.Thumbnail", new FileUploadField('Thumbnail', 'Thumbnail'));

          $fields->addFieldToTab("Root.Content.Banners", new MultipleImageUploadField('BannerFiles','Upload several banner files'));
    //...
       return $fields;
       }

    On seemingly random pages I get the error:

    [User Error] Couldn't run query: SELECT "File"."ClassName", "File"."Created", "File"."LastEdited", "File"."Name", "File"."Title", "File"."Filename", "File"."Content", "File"."Sort", "File"."SortOrder", "File"."ParentID", "File"."OwnerID", "BannerFile"."PagesID", "File"."ID", CASE WHEN "File"."ClassName" IS NOT NULL THEN "File"."ClassName" ELSE 'File' END AS "RecordClassName" FROM "File" LEFT JOIN "BannerFile" ON "BannerFile"."ID" = "File"."ID" WHERE ("File"."ClassName" IN ('Image','BannerFile','Image_Cached')) AND (ID = '22') ORDER BY SortOrder ASC LIMIT 1 Column 'ID' in where clause is ambiguous
    GET /site/3d-scanners/accessories/?flush=1

    Line 536 in G:\localhost\site\sapphire\core\model\MySQLDatabase.php

    The images are shown correctly for the test pages where I assigned images too. On random other pages (both with and without banner images added) I get the above error.

    If I change Image to File in the BannerFile class the error disappears.

    BannerFile.php:

    class BannerFile extends File {

       static $has_one = array (
          'Pages' => 'Page'
       );

    }

    Can I only use the File class and not the Image class with the new Uploadify Class? Or is there a bug somewhere else?

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Bug Reports Link to this post

    I think you might need your relation to be;

    public static $has_many = array(
    'BannerFile' => 'BannerFile'
    );

  • MarijnKampf
    Avatar
    Community Member
    150 Posts

    Re: Bug Reports Link to this post

    Hi Mattclegg,

    Thanks for making a suggestions, it makes no difference though. The error remains.

    I may completely review my approach, as I'm actually looking for a many_many relation rather than a has_many. A well, back to the drawing board.

    Marijn.

  • brice
    Avatar
    Community Member
    50 Posts

    Re: Bug Reports Link to this post

    I am having trouble with SortableDataObject when limiting a relationship getter. When I declare it on an object with a many-many relationship, and then use the getManyManyCompenents() call to fetch relations -- it works as expected. If I supply a limit to the getManymanyComponents() call... it complains of an all distinct duplicate SortOrder column.

    This issue was brought up by Tony in;

    http://www.silverstripe.org/data-model-questions/show/284045?start=0#post289062

    I hope to use:

    $group = $this->owner->SpotlightGroup();
    return $group->getManyManyComponents("Spotlights",'Status="valid"','','',$group->Slots);

    But am currently forced to use the more inefficient:

    $group = $this->owner->SpotlightGroup();
    $groupSet = $group->getManyManyComponents("Spotlights",'Status="valid"');
    $mySet = new DataObjectSet();
    $count = intval($group->Slots);
    while($count)
    {
       $count--;
       $mySet->push($groupSet->shift());
    }
    return $mySet;

    It seems the AugmentSQL of SortableDataObject returns the same object, so I am not sure where to look further...

  • UncleCheese
    Avatar
    4085 Posts

    Re: Bug Reports Link to this post

    You're using SortableDataObject::add_sortable_many_many_relation()?

    ---------------
    Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

  • MarcusDalgren
    Avatar
    Community Member
    287 Posts

    Re: Bug Reports Link to this post

    I just wanted to report that I'm having the same issue as Nimblor, ManyManyDataObjectManager does not work unless default sort is set since the ORDER BY clause gets added anyway but ends up being empty.

    Running SilverStripe 2.4.2 with the latest SVN of DataObject Manager.
    His suggested fix for changing line 104 works as far as I can see.

  • brice
    Avatar
    Community Member
    50 Posts

    Re: Bug Reports Link to this post

    UncleCheese ->

    Yes, I am calling

    SortableDataObject::add_sortable_many_many_relation('SpotlightGroup','Spotlights');

    Here's a simple test:

    // Module code / Class Files
    class SpotlightGroup extends DataObject {

       static $db = array(
          'Title' => 'Varchar',
          'Slots' => 'Int',
       );

    static $has_many = array('Pages' => 'Page');

       static $many_many = array('Spotlights' => 'Spotlight');
    }

    class Spotlight extends DataObject {

       static $db = array(
        "Title"       => "Varchar",
          "Caption"      => "Varchar",
          "ExternalLink"   => "Varchar",
    );

       static $belongs_many_many = array('SpotlightGroups' => 'SpotlightGroup');
    }

    class SpotlightPageDecorator extends DataObjectDecorator {
    function extraStatics()
       {
          return array(
             'has_one'   => array('SpotlightGroup' => 'SpotlightGroup')
          );
       }

    function MySpotlights()
    {
    $group = $this->owner->SpotlightGroup();
    return $group->getManyManyComponents("Spotlights",'Status="valid"','','',$group->Slots);
    }

    }

    // Module _config.php
    Object::add_extension('Page','SpotlightPageDecorator');
    SortableDataObject::add_sortable_many_many_relation('SpotlightGroup','Spotlights');

    // template:

    <% control MySpotlights %>
    $Title
    <% end_control %>

    37846 Views
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
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.