Skip to content

Commit

Permalink
FIX: Save repeated database queries to fetch elemental area name (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kinglozzer committed Aug 21, 2023
1 parent 4b19889 commit 3ae7363
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,9 @@ public function getAreaRelationName()

if ($page) {
$has_one = $page->config()->get('has_one');
$area = $this->Parent();
$class = DataObject::getSchema()->hasOneComponent($this, 'Parent');
$area = ($this->ParentID) ? DataObject::get_by_id($class, $this->ParentID) : null;
$area = $area ?: ElementalArea::singleton();

foreach ($has_one as $relationName => $relationClass) {
if ($page instanceof BaseElement && $relationName === 'Parent') {
Expand Down

0 comments on commit 3ae7363

Please sign in to comment.