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