How do I get a list of classes that are subclasses of 2 unrelated classes?
I need to get a list of all classes that are subclasses of two unrelated classes.
For example I want to get a list of all classes that are both:
- Persistent (extends %Library.Persistent)
- XML-Enabled (extends %XML.Adaptor)
To get subclasses of one class I can use this query:
set rs = ##class(%Dictionary.ClassDefinitionQuery).SubclassOfFunc("%Library.Persistent")
But what about two classes?
I suppose I can run this query twice, build two $lb, then iterate over one of them and build a new $lb with classes that appear in both lists. Are there any better approaches?
This condition:
Is insufficient. Consider this case:
While Package.ClassC satisfies both conditions (it's a subclass of both %Library.Persistent and %XML.Adaptor), it would not be returned by the SQL query, as Super field does not contain required superclasses directly.
But we can easily join 2 SubclassOf queries via SQL:
Here's an article on useful autogenerated methods for properties, indices, queries, etc.
Here's a write-up on defining your own query types to add more methods than just Func().
You may do it as well with SQL
select 'PERS' Typ, ID from %Dictionary.ClassDefinition
where Super [ 'Persistent'
union all
select 'XML' Typ, ID from %Dictionary.ClassDefinition
where Super [ 'XML.Adaptor'
)
group by ID
order by cnt desc
Result : 2 both classes contained in class
You are right, the A -B -C case isn't covered by me:
)
not a goal but an assist (half points
I must admit I was unfamiliar with the xxxFunc() syntax Eduard's code used. So I decided to track it down in the documentation:
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...
That comes from the 2012.2 release notes and reads as follows:
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue