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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Bug Reports


Reply

297 Posts   49779 Views

Avatar
MarijnKampf

17 September 2010 at 6:42pm Community Member, 164 Posts

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.

Avatar
brice

29 September 2010 at 12:29pm Community Member, 51 Posts

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

Avatar
UncleCheese

29 September 2010 at 2:34pm 4085 Posts

You're using SortableDataObject::add_sortable_many_many_relation()?

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

Avatar
MarcusDalgren

30 September 2010 at 1:32am Community Member, 288 Posts

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.

Avatar
brice

30 September 2010 at 5:58am Community Member, 51 Posts

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 %>

Avatar
brice

1 October 2010 at 1:25pm Community Member, 51 Posts

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 ?

Avatar
UncleCheese

1 October 2010 at 1:54pm 4085 Posts

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

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

Avatar
brice

2 October 2010 at 7:22am Community Member, 51 Posts

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;