Get the parent category
518771
def parent(self):
        
        if self.path:
            return Category(os.path.dirname(self.path))
        return None
1259239
public function getParent()
    {
        if (\is_string($this->parent)) {
            $parent = TypeCollection::getInstance()->getTypeByName($this->parent);
            \assert($parent instanceof ObjectType);

            return $parent;
        }

        return $this->parent;
    }
839473
public function getParentCategory()
    {
        $oCat = null;

        // loading only if parent id is not rootid
        if ($this->oxcategories__oxparentid->value && $this->oxcategories__oxparentid->value != 'oxrootid') {
            // checking if object itself has ref to parent
            if ($this->_oParent) {
                $oCat = $this->_oParent;
            } else {
                $oCat = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
                if (!$oCat->load($this->oxcategories__oxparentid->value)) {
                    $oCat = null;
                } else {
                    $this->_oParent = $oCat;
                }
            }
        }

        return $oCat;
    }
1172040
private function ParentItem()
    {
        $this->parent = $this->GetTreeItem('parent');
        return $this->parent->Exists() ? $this->parent : null;
    }
688672
def get_parent(self, update=False):
        """"""
        if self._meta.proxy_for_model:
            # the current node is a proxy model; the returned parent
            # should be the same proxy model, so we need to explicitly
            # fetch it as an instance of that model rather than simply
            # following the 'parent' relation
            if self.parent_id is None:
                return None
            else:
                return self.__class__.objects.get(pk=self.parent_id)
        else:
            return self.parent
498608
public function getSubCategory($list_category, $current_parent = NULL, $parent_id = 0, $char = '')
    {
        if (count($list_category) > 0) {
            foreach ($list_category as $key => $category) {
                if ($category->parent == $parent_id) {
                    $selected = $current_parent == $category->id ? 'selected' : '';
                    echo '<option ' . $selected . ' value="' . $category->id . '">' . $char . ' ' . $category->name . '</option>';
                    unset($list_category[$key]);
                    self::getSubCategory($list_category, $current_parent, $category->id, $char . '----');
                }
            }
        }
    }
321297
def get_category(category_string, model=Category):
    
    model_class = get_cat_model(model)
    category = str(category_string).strip("'\"")
    category = category.strip('/')

    cat_list = category.split('/')
    if len(cat_list) == 0:
        return None
    try:
        categories = model_class.objects.filter(name=cat_list[-1], level=len(cat_list) - 1)
        if len(cat_list) == 1 and len(categories) > 1:
            return None
        # If there is only one, use it. If there is more than one, check
        # if the parent matches the parent passed in the string
        if len(categories) == 1:
            return categories[0]
        else:
            for item in categories:
                if item.parent.name == cat_list[-2]:
                    return item
    except model_class.DoesNotExist:
        return None
1256094
public function &GetParent()
    {
        $oParent = null;
        if (!empty($this->fieldShopCategoryId)) {
            $oParent = TdbShopCategory::GetNewInstance();
            $oParent->SetLanguage($this->iLanguageId);
            if (!$oParent->Load($this->fieldShopCategoryId)) {
                $oParent = null;
            }
        }

        return $oParent;
    }
37236
def parent(self):
        """"""
        if self._parent is None:
            if self.pid is not None:
                self._parent = self.api._load_directory(self.pid)
        return self._parent
1272604
def get(self, *args, **kwargs):
        """"""
        self.initial = {"category_name":  kwargs.get('category_name', None)}
        return super(CategoryFormView, self).get(*args, **kwargs)
1312925
public function parentTag(): ?string
    {
        switch ($this->attributes['list']) {
            case Options::ATTRIBUTE_LIST_ORDERED:
                return Options::HTML_TAG_LIST_ORDERED;
                break;
            case Options::ATTRIBUTE_LIST_BULLET:
                return Options::HTML_TAG_LIST_UNORDERED;
                break;

            default:
                return Options::HTML_TAG_LIST_UNORDERED;
                break;
        }
    }
1276895
def parents(self):
        
        parents = []

        if self.parent is None:
            return []

        category = self
        while category.parent is not None:
            parents.append(category.parent)
            category = category.parent

        return parents[::-1]
1034403
def get_parent(self):
        """"""
        if not self.has_cached_parent:
            if self.parent is not None:
                self._parent_block = self.runtime.get_block(self.parent)
            else:
                self._parent_block = None
            self._parent_block_id = self.parent
        return self._parent_block
950835
private function findCategoriesWithoutParents()
    {
        // get categories that have no parent but depth > 0
        $qb = $this->categoryRepository->createQueryBuilder('c2')
            ->select('count(c2.id)')
            ->leftJoin('c2.parent', 'c1')
            ->where('c2.depth <> 0 AND c2.parent IS NULL');

        return $qb->getQuery()->getSingleScalarResult();
    }
1062735
public function get_parent_category() {
        if ($this->is_category_item() or $this->is_course_item()) {
            return $this->get_item_category();

        } else {
            return grade_category::fetch(array('id'=>$this->categoryid));
        }
    }
108228
public function getCategoriesTree()
    {
        $allCategories = $this->getCategories();
        $topCategories = [];

        $currentCategory = null;

        // Building tree from categories collection
        foreach ($allCategories as $idCat => $category) {

            // If level, we put category in an array with only top level categories.
            $topLevel = 2; // 1 is root category
            if ($category->getLevel() == $topLevel && !isset($topCategories[$idCat])) {
                $topCategories[$idCat] = $category;
            } else {
                // Foreach categories with sub category we add a child to the parent
                if (!isset($allCategories[$category->getParentId()])) {
                    // Ignore if no parent
                    continue;
                }
                $parent           = $allCategories[$category->getParentId()];
                $children         = $parent->getData('_children') ?: [];
                $children[$idCat] = $category;
                $category->setData('_parent', $parent);
                $parent->setData('_children', $children);
            }

            if ((int) $idCat === $this->getCurrentCategoryId()) {
                $currentCategory = $category;
            }
        }

        // Set current path
        if (null !== $currentCategory) {
            $setCategoryAsCurrent = function (Mage_Catalog_Model_Category $category, $isParent = false) use (&$setCategoryAsCurrent) {
                if ($isParent) {
                    $category->setContainsCurrentCategory(true);
                } else {
                    $category->setIsCurrentCategory(true);
                }
                if ($parentCategory = $category->getData('_parent')) {
                    $setCategoryAsCurrent($parentCategory, true);
                }
            };
            $setCategoryAsCurrent($currentCategory);
        }

        return $topCategories;
    }
652501
public function getParentsList()
    {
        /** @var static $root */
        $root  = static::root();
        $items = [
            ['id' => '1', 'title' => 'Item Root'],
        ];

        if ($this->exists) {
            $parents = $this->ancestors()
                            ->withoutRoot()
                            ->orWhere(function ($query) {
                                $query->where('depth', $this->depth)->where('id', '<>', $this->id);
                            })
                            ->get();
            foreach ($parents as $parent) {
                $items[] = [
                    'title' => $parent->present()->indentedTitle(),
                    'id'    => $parent->id,
                ];
            }
        } else {
            foreach ($root->getDescendants() as $parent) {
                $items[] = [
                    'title' => $parent->present()->indentedTitle(),
                    'id'    => $parent->id,
                ];
            }
        }

        return array_pluck($items, 'title', 'id');
    }