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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Bug Reports


Go to End


297 Posts   102002 Views

Avatar
MarijnKampf

Community Member, 176 Posts

17 September 2010 at 6:42pm

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

Community Member, 52 Posts

29 September 2010 at 12:29pm

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

Forum Moderator, 4102 Posts

29 September 2010 at 2:34pm

You're using SortableDataObject::add_sortable_many_many_relation()?

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

Avatar
MarcusDalgren

Community Member, 288 Posts

30 September 2010 at 1:32am

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

Community Member, 52 Posts

30 September 2010 at 5:58am

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

Community Member, 52 Posts

1 October 2010 at 1:25pm

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

Forum Moderator, 4102 Posts

1 October 2010 at 1:54pm

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

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

Avatar
brice

Community Member, 52 Posts

2 October 2010 at 7:22am

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;