mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Fixed Hierarchy::liveChildren() to work on PostgreSQL
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@87210 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
b8617a5cab
commit
45fb4e0182
@ -517,19 +517,31 @@ class Hierarchy extends DataObjectDecorator {
|
||||
|
||||
$baseClass = ClassInfo::baseDataClass($this->owner->class);
|
||||
|
||||
$filter = "\"{$baseClass}\".\"ParentID\" = " . (int)$this->owner->ID
|
||||
. " AND \"{$baseClass}\".\"ID\" != " . (int)$this->owner->ID;
|
||||
|
||||
if($onlyDeletedFromStage) {
|
||||
// Note that the lack of double-quotes around $baseClass are the only thing preventing
|
||||
// it from being rewritten to {$baseClass}_Live. This is brittle, won't work in
|
||||
// postgres, and will need to be fixed *somehow*. Also, this code should probably be
|
||||
// refactored to be pushed into Versioned somehow; perhaps a "doesn't exist on stage X"
|
||||
// option for get_by_stage.
|
||||
// it from being rewritten to {$baseClass}_Live. This is brittle and a little clumsy
|
||||
$join = "LEFT JOIN {$baseClass} ON {$baseClass}.\"ID\" = \"{$baseClass}\".\"ID\"";
|
||||
$extraFilter .= " AND {$baseClass}.\"ID\" IS NULL";
|
||||
$filter .= " AND {$baseClass}.\"ID\" IS NULL";
|
||||
}
|
||||
|
||||
return Versioned::get_by_stage($baseClass, "Live", "\"{$baseClass}\".\"ParentID\" = "
|
||||
. (int)$this->owner->ID . " AND \"{$baseClass}\".\"ID\" != " . (int)$this->owner->ID
|
||||
. $extraFilter, null, $join);
|
||||
$oldStage = Versioned::current_stage();
|
||||
Versioned::reading_stage('Live');
|
||||
|
||||
$query = $this->owner->extendedSQL($filter, null, null, $join);
|
||||
|
||||
// Since we didn't include double quotes in the join & filter, we need to add them into the
|
||||
// SQL now, after Versioned has done is query rewriting
|
||||
$correctedSQL = str_replace(array("LEFT JOIN {$baseClass}", "{$baseClass}.\"ID\""),
|
||||
array("LEFT JOIN \"{$baseClass}\"", "\"{$baseClass}\".\"ID\""), $query->sql());
|
||||
|
||||
$result = $this->owner->buildDataObjectSet(DB::query($correctedSQL));
|
||||
|
||||
Versioned::reading_stage($oldStage);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user