Skip to content

Commit

Permalink
FIX Ensure Versioned query has table name prefix so it will work with…
Browse files Browse the repository at this point in the history
… modules like fluent
  • Loading branch information
robbieaverill committed Sep 10, 2018
1 parent 0e3c17a commit 7583b4c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public function getOwnerPage()

if ($this->OwnerClassName) {
$class = $this->OwnerClassName;
$tableName = DataObject::getSchema()->tableName($class);
$instance = Injector::inst()->get($class);
if (!ClassInfo::hasMethod($instance, 'getElementalRelations')) {
return null;
Expand All @@ -167,7 +168,7 @@ public function getOwnerPage()
$areaID = $eaRelationship . 'ID';

$currentStage = Versioned::get_stage() ?: Versioned::DRAFT;
$page = Versioned::get_one_by_stage($class, $currentStage, "\"$areaID\" = {$this->ID}");
$page = Versioned::get_one_by_stage($class, $currentStage, "\"$tableName\".\"$areaID\" = {$this->ID}");

if ($page) {
$this->cacheData['owner_page'] = $page;
Expand All @@ -177,6 +178,7 @@ public function getOwnerPage()
}

foreach ($this->supportedPageTypes() as $class) {
$tableName = DataObject::getSchema()->tableName($class);
$instance = Injector::inst()->get($class);
if (!ClassInfo::hasMethod($instance, 'getElementalRelations')) {
return null;
Expand All @@ -185,7 +187,7 @@ public function getOwnerPage()

foreach ($elementalAreaRelations as $eaRelationship) {
$areaID = $eaRelationship . 'ID';
$page = Versioned::get_one_by_stage($class, Versioned::DRAFT, "\"$areaID\" = {$this->ID}");
$page = Versioned::get_one_by_stage($class, Versioned::DRAFT, "\"$tableName\".\"$areaID\" = {$this->ID}");

if ($page) {
if ($this->OwnerClassName !== $class) {
Expand Down

0 comments on commit 7583b4c

Please sign in to comment.