Book a Demo

Author Topic: retrieving the parent element of current element  (Read 3980 times)

ron10023

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
retrieving the parent element of current element
« on: March 23, 2008, 07:53:24 pm »
Hi everybody,

Is there a way to get the parent of a specific element?

When i try to use the ParentID attribute it always contains zero

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: retrieving the parent element of current eleme
« Reply #1 on: March 23, 2008, 10:05:54 pm »
Hi Ron,

Think about what you mean by "parent" and this will clear up quickly.

An element - at least an element in EA - always resides in (belongs to) a package. So there should always be a valid PackageID property. [Yes, I know there is an exception for Models (i.e. root packages) but that's not what you're talking about here.]

So for many situations the 'parent' of an element is the package that contains it. That's often how you will navigate the model hierarchy.

However, some elements are directly 'owned' by other elements. This can happen in the case of Class elements, which can contain other classes, embedded elements of various types, or some other situations. In these cases - and only in these cases - the ParentID of the 'child' element is populated with the ElementID of the 'parent.' In other cases the ParentID of the should be set to 0. When ParentID is set to 0 it indicates that this element is contained directly by the package, and not by another (intervening) element.

The above paradigm always works out in EA, because to be owned of an element, something must be owned by the same package as the element. I suspect - without proof, but I'd not care to test this on an important project - that if you built a project and got the PackageID of parent and child elements out of sync you would come to grief somewhere down the line.

HTH, David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: retrieving the parent element of current eleme
« Reply #2 on: March 25, 2008, 08:30:32 am »
Quote
The above paradigm always works out in EA, because to be owned of an element, something must be owned by the same package as the element. I suspect - without proof, but I'd not care to test this on an important project - that if you built a project and got the PackageID of parent and child elements out of sync you would come to grief somewhere down the line.
It won't show up as you expect in the project browser.  However, it's a problem that can be fixed by the integrity checker.