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

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

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

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

9 October 2010 at 10:41am
Running against latest trunk.
I've come across a bug where *FileDataObjectManagers throw an exception if the source class has summary_fields which pull in the value of a relative -- e.g.
static $has_one = array(
"File" => "Image"
);static $summary_fields = array(
'Title' => 'Photo Title',
'File.Name' => 'Filename',
'CMSThumbnail' => 'Thumbnail',
);The getQuery() methods of the ManyMany & HasOne FileDataObjectManagers are the cause; they generate a query that does not include the related table.
My recommendation is to relate more closely to the ComplexTableField classes & their derivatives [ManyManyComplexTableField, etc.].. and to use parent:: methods as often as possible to alleviate maintenacne in DOM.
Anyway attached is a patch that fixes this... although an above approach would be best (e.g. a simple overload of getQuery that calls parent::getQuery() & then injects the WHERE for relatedOnly).
Index: www/dataobject_manager/code/HasManyFileDataObjectManager.php
===================================================================
--- www/dataobject_manager/code/HasManyFileDataObjectManager.php (revision 90)
+++ www/dataobject_manager/code/HasManyFileDataObjectManager.php (working copy)
@@ -58,23 +58,23 @@
function getQuery($limitClause = null) {
if($this->customQuery) {
- $query = $this->customQuery;
+ $query = clone $this->customQuery;
$query->select[] = "{$this->sourceClass}.ID AS ID";
$query->select[] = "{$this->sourceClass}.ClassName AS ClassName";
$query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName";
}
else {
- $query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin);
+ $query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter(), $this->sourceSort, $limitClause, $this->sourceJoin);
// Add more selected fields if they are from joined table.- $SNG = singleton($this->sourceClass);
+ /*$SNG = singleton($this->sourceClass);
foreach($this->FieldList() as $k => $title) {
if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k))
$query->select[] = $k;
- }
+ }*/
}
- return clone $query;
+ return $query;
}
public function setParentClass($class)
Index: www/dataobject_manager/code/ManyManyFileDataObjectManager.php
===================================================================
--- www/dataobject_manager/code/ManyManyFileDataObjectManager.php (revision 90)
+++ www/dataobject_manager/code/ManyManyFileDataObjectManager.php (working copy)
@@ -132,21 +132,21 @@
function getQuery($limitClause = null) {
if($this->customQuery) {
- $query = $this->customQuery;
+ $query = clone $this->customQuery;
$query->select[] = "{$this->sourceClass}.ID AS ID";
$query->select[] = "{$this->sourceClass}.ClassName AS ClassName";
$query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName";
}
else {
- $query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin);
+ $query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter(), $this->sourceSort, $limitClause, $this->sourceJoin);
// Add more selected fields if they are from joined table.- $SNG = singleton($this->sourceClass);
+ /*$SNG = singleton($this->sourceClass);
foreach($this->FieldList() as $k => $title) {
if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k))
$query->select[] = $k;
- }
+ }*/
$parent = $this->controllerClass();
$mm = $this->manyManyTable;
$if_clause = "IF(`$mm`.`{$this->manyManyParentClass}ID` IS NULL, '0', '1')";
@@ -155,7 +155,7 @@
if($this->OnlyRelated())
$query->where[] = $if_clause;
}
- return clone $query;
+ return $query;
}Also avail @ http://pastebin.com/J4YNf0kW
-
Re: Bug Reports

10 October 2010 at 4:40am
Hi UncleCheeze!
I'm using a simple DataObjectManager an experiencing some problems with the Sort feature. When I load the page, in the CMS, it sorts well. but If I edit an element, then it sorts it A-Z instead of Z-A like I specified.
Here's the code:
$fields->addFieldToTab("Root.Content.Presse", new DataObjectManager (
$this,
'PressArticles',
'PressArticle',
array('ArticleTitle' => 'Titre', 'Date'=>'Date', 'Newspaper'=>'Journal', 'Journalist'=>'Journaliste'),
'getCMSFields_forPopup',
"", 'Date DESC'
));Thanks for you help!
-
Re: Bug Reports

19 October 2010 at 11:11pm
Hi Uncle
I posted a bug here: http://code.google.com/p/dataobjectmanager/issues/detail?id=3
Cheers
Nicolaas
-
Re: Bug Reports

9 November 2010 at 2:46am Last edited: 9 November 2010 2:50am
Using SS 2.4.3-rc2, DataObjectManager trunk (revision 511).
Wrong generated edit link
Have following code:
class MassMediaArticle extends DataObject {
static $db = array (
'PubDate' => 'Date',
'Header' => 'Varchar(255)',
'URL' => 'Varchar(255)',
'Source' => 'Varchar(255)',
'SourceURL' => 'Varchar(255)',
'Summary' => 'HTMLText'
);
static $has_one = array (
'MassMediaArticlesPage' => 'MassMediaArticlesPage'
);
public function getCMSFields_forPopup()
{
$dateField = new DateField('PubDate');
$dateField->setConfig('showcalendar', true);
$dateField->setConfig('dateformat', 'dd.MM.YYYY');
return new FieldSet(
$dateField,
new TextField('Header'),
new TextField('URL'),
new TextField('Source'),
new TextField('SourceURL'),
new SimpleTinyMCEField('Summary')
);
}
}And in Page class:
class MassMediaArticlesPage extends Page {
static $has_many = array (
'MassMediaArticles' => 'MassMediaArticle'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new DataObjectManager(
$this,
'MassMediaArticles',
'MassMediaArticle',
array('PubDate' => 'Publication Date', 'Header' => 'Header', 'Source' => 'Source' ),
'getCMSFields_forPopup'
);
$f->addFieldToTab("Root.Content.MassMediaArticles", $manager);
return $f;
}
}In CMS DOM generate following string for edit object like this:
http://localhost:8888/mysite/admin/EditForm/field/MassMediaArticles/item/5?SecurityID=423222417/edit?ctf[MassMediaArticles][start]=0&ctf[MassMediaArticles][per_page]=10&ctf[MassMediaArticles][showall]=0&ctf[MassMediaArticles][sort]=SortOrder&ctf[MassMediaArticles][sort_dir]=&ctf[MassMediaArticles][search]=&ctf[MassMediaArticles][filter]=
But it wrong, and popup window only show object fields (like "readonly"), all fields is inactive (call method "view"). I saw link what generated by ComplexTableField and correct above link to:
http://localhost:8888/mysite/admin/EditForm/field/MassMediaArticles/item/5/edit?SecurityID=423222417&ctf[MassMediaArticles][start]=0&ctf[MassMediaArticles][per_page]=10&ctf[MassMediaArticles][showall]=0&ctf[MassMediaArticles][sort]=SortOrder&ctf[MassMediaArticles][sort_dir]=&ctf[MassMediaArticles][search]=&ctf[MassMediaArticles][filter]=
And voila! DOM show me necessary edit popup window. Error in this part of URL - "item/5?SecurityID=423222417/edit?" instead of "item/5/edit?SecurityID=423222417&". I suppose, what this bug appear because following functions in DataObjectManager_Item not expect in URL "?SecurityID=":
function Link() {
return Controller::join_links($this->parent->BaseLink(), '/item/' . $this->item->ID);
}public function EditLink()
{
return $this->Link()."/edit?".$this->parent->getQueryString();
}Thank you for attention, and for DOM
In awaiting of fix this issue
-
Re: Bug Reports

9 November 2010 at 3:36am
I fix EditLink() function as below:
public function EditLink()
{
return Controller::join_links($this->Link(), "/edit?".$this->parent->getQueryString());
}It work!
| 37842 Views | ||
| Go to Top | Next > |


