Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Bug Reports

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, 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: 49493 Views
  • MarijnKampf
    Avatar
    Community Member
    164 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
    51 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
    288 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
    51 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 %>

  • brice
    Avatar
    Community Member
    51 Posts

    Re: Bug Reports Link to this post

    Should I be calling a different method to retrieve a limited component set (limited # of many-many related objects) ?

    E.g. vs:

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

    something like

    $group->Spotlights("limit 10");

    I see the the ManyManyDataObjectManger itself uses a custom query generator in its getQuery method, which I am assuming successfully introduces a limit.

    Is this considered a "bug" in SortableDataObject ?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Bug Reports Link to this post

    I think you can just do $obj->YourManyMany($fitler, $limit);

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

  • brice
    Avatar
    Community Member
    51 Posts

    Re: Bug Reports Link to this post

    Unclecheese,

    The syntax for that is something like:

    return $group->Spotlights("Status='valid'",null,null,1);

    And again -- the same SortableDataObject bug. Below is the exception noting duplicate column:

    [User Error] Couldn't run query: SELECT count(*) FROM SELECT "Spotlight"."ClassName", "Spotlight"."Created", "Spotlight"."LastEdited", "Spotlight"."Title", "Spotlight"."Caption", "Spotlight"."ExternalLink", "Spotlight"."Status", "Spotlight"."SortOrder", "Spotlight"."ThumbnailID", "Spotlight"."PosterImageID", "Spotlight"."MediaID", "Spotlight"."PageID", "Spotlight"."ID", CASE WHEN "Spotlight"."ClassName" IS NOT NULL THEN "Spotlight"."ClassName" ELSE 'Spotlight' END AS "RecordClassName", "SpotlightGroup_Spotlights"."SortOrder" FROM "Spotlight" INNER JOIN "SpotlightGroup_Spotlights" ON "SpotlightGroup_Spotlights"."SpotlightID" = "Spotlight"."ID" WHERE ("SpotlightGroup_Spotlights"."SpotlightGroupID" = 1) AND (Status='valid') GROUP BY "Spotlight"."ClassName", "Spotlight"."Created", "Spotlight"."LastEdited", "Spotlight"."Title", "Spotlight"."Caption", "Spotlight"."ExternalLink", "Spotlight"."Status", "Spotlight"."SortOrder", "Spotlight"."ThumbnailID", "Spotlight"."PosterImageID", "Spotlight"."MediaID", "Spotlight"."PageID", "Spotlight"."ID", CASE WHEN "Spotlight"."ClassName" IS NOT NULL THEN "Spotlight"."ClassName" ELSE 'Spotlight' END, "SpotlightGroup_Spotlights"."SortOrder") all_distinct Duplicate column name 'SortOrder'

    Have you been able to repeat this? I'm having to use a inefficient workaround (below)

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

    49493 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.