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
| Go to End | Next > | |
| Author | Topic: | 37743 Views |
-
Re: Bug Reports

16 September 2010 at 5:31pm
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 ;)
-
Re: Bug Reports

17 September 2010 at 2:00am
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=1Line 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?
-
Re: Bug Reports

17 September 2010 at 1:31pm
I think you might need your relation to be;
public static $has_many = array(
'BannerFile' => 'BannerFile'
); -
Re: Bug Reports

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.
-
Re: Bug Reports

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...
-
Re: Bug Reports

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 -
Re: Bug Reports

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. -
Re: Bug Reports

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 %>
| 37743 Views | ||
| Go to Top | Next > |



