Parent has to be different from itself.
490189
def validate_parent_id(self, key, parent_id):
        """"""
        id_ = getattr(self, 'id', None)
        if id_ is not None and parent_id is not None:
            assert id_ != parent_id, 'Can not be attached to itself.'
        return parent_id
1219663
def _is_parent_of(parent, child):
    """"""
    if child.is_partition:
        return child.partition_slave == parent
    if child.is_toplevel:
        return child.drive == parent and child != parent
    return False
1316748
public void adoptParent(ElementBox parent)
    {
        if (parent instanceof BlockBox)
            setContainingBlockBox(parent);
        else
            setContainingBlockBox(parent.getContainingBlockBox());
        setParent(parent);
        setViewport(parent.getViewport());
        setClipBlock(parent.getClipBlock());
    }
474995
def parent(self, parent_object, limit_parent_language=True):
        
        return self.all().parent(parent_object, limit_parent_language)
865032
def getparent(self, profile):
        """"""
        assert self.parent
        for inputtemplate in profile.input:
            if inputtemplate == self.parent:
                return inputtemplate
        raise Exception("Parent InputTemplate '"+self.parent+"' not found!")
570627
private void setParent(DepTreeNode parent) {
		if (this.name.length() == 0) {
			// A child node must have a name.
			throw new IllegalStateException();
		}
		this.parent = new WeakReference<DepTreeNode>(parent);
	}
539790
def fill_parentidid2obj_r0(self, id2obj, child_obj):
        """"""
        for parent_obj in child_obj.parents:
            if parent_obj.item_id not in id2obj:
                id2obj[parent_obj.item_id] = parent_obj
                self.fill_parentidid2obj_r0(id2obj, parent_obj)
972519
function (theparent) {
            if (this.parent() !== null)
                this.detach();
            var children = theparent.children();
            children.push(this);
            theparent.children(children);
            this.parent(theparent);
        }
1073087
def eq_or_parent(self, other):
        
        return self.parts[: len(other.parts)] == other.parts[: len(self.parts)]
754973
def :
        """"""
        CheckParent(self)

        return _fitz.Annot_
1325839
def parent(self, parent):
        
        self._parent = parent
        self.graph.add(
            (self.asNode(), RDF_NAMESPACES.CAPITAINS.parent, parent.asNode())
        )
        parent._add_member(self)
154811
private void allowLoneBlock(Node parent) {
    if (loneBlocks.isEmpty()) {
      return;
    }

    if (loneBlocks.peek() == parent) {
      loneBlocks.pop();
    }
  }
140837
def add_to_parent(self):
        """"""
        parent = self.parent
        if parent is not None:
            try:
                children = parent.children
            except AttributeError: pass
            else:
                include(children, self)
63573
def top_parent(self):
        
        parent = self.parent
        while parent is not None:
            if parent.parent is None:
                return parent
            else:
                parent = parent.parent
        return self
190376
def change_parent(sender, instance, **kwargs):
    
    if instance.id is None:
        return
    if len({'term', 'term_id'} & set(instance.changed_fields)) != 0:
        diff = instance.diff
        parent = diff['term'][0] if 'term' in diff else diff['term_id'][0]
        child_id = instance.item_id
        if parent is not None:
            parent_id = parent.item_id if isinstance(parent, Term) else Term.objects.get(pk=parent).item_id
            ItemRelation.objects.filter(parent_id=parent_id, child_id=child_id).delete()
        ItemRelation.objects.get_or_create(parent_id=instance.term.item_id, child_id=child_id, visible=True)
    if len({'term_secondary', 'term_secondary_id'} & set(instance.changed_fields)) != 0:
        diff = instance.diff
        child_id = instance.item_id
        parent = diff['term_secondary'][0] if 'term_secondary' in diff else diff['term_secondary_id'][0]
        if parent is not None:
            parent_id = parent.item_id if isinstance(parent, Term) else Term.objects.get(pk=parent).item_id
            ItemRelation.objects.filter(parent_id=parent_id, child_id=child_id).delete()
        if instance.term_secondary is not None or instance.term_secondary_id is not None:
            ItemRelation.objects.get_or_create(parent_id=instance.term_secondary.item_id, child_id=child_id, visible=True)
    if len({'context', 'context_id'} & set(instance.changed_fields)) != 0:
        diff = instance.diff
        parent = diff['context'][0] if 'context' in diff else diff['context_id'][0]
        child_id = instance.item_id
        if parent is not None:
            parent_id = parent.item_id if isinstance(parent, Context) else Context.objects.get(pk=parent).item_id
            ItemRelation.objects.filter(parent_id=parent_id, child_id=child_id).delete()
        ItemRelation.objects.get_or_create(parent_id=instance.context.item_id, child_id=child_id, visible=True)
114328
def remove_from_parent(self):
        """"""
        parent = self.parent
        if parent is not None:
            try:
                children = parent.children
            except AttributeError: pass
            else:
                remove_upto_once(children, self)
678829
function hasParentRule(rule) {
  if (!rule.parent) {
    return false
  }

  if (rule.parent.type === 'rule') {
    return true
  }

  return hasParentRule(rule.parent)
}