I like this approach. I created a server side function named
:GetClassAncestors
var g = orient.getGraphNoTx();
var classLookup = {};
var classSchema = g.command("sql", "select name, superClass from ( select
expand(classes) from metadata:schema)");
for(var i=0; i < classSchema.length; i++) {
var schemaClass = classSchema[i];
var className = schemaClass.getRecord().field('name')
var parentName = schemaClass.getRecord().field('superClass')
classLookup[className] = parentName;
};
var objectAncestors = [];
var objectAncestor = objectClassName;
while(objectAncestor != null)
{
objectAncestors[objectAncestors.length] = objectAncestor;
objectAncestor = classLookup[objectAncestor]
}
return objectAncestors;
You then call it: "select GetClassAncestors(@class) from #15:2"
On Sunday, August 2, 2015 at 11:20:40 AM UTC-4, nagaraja sosale ramaswamy
wrote:
>
> a possible solution is to write a simple server side function which
> performs the query against the metadata:schema special target and finds the
> ancestors. then you could use the function in your sql query, like 'select
> ancestorClasses(@rid) from #15:2'
>
> such a function itself could be developed using this query gets the
> immediate ancestor for given @rid:
>
> select superClasses from ( select expand(classes) from metadata:schema )
> where name in (select @class from #15:2) unwind superClasses
>
> then you could recurse over the superClasses to obtain the complete
> hierarchy.
>
> This approach can be easily extended to handle the case of multiple
> inheritance
>
>
> On Saturday, August 1, 2015 at 2:45:00 AM UTC+5:30, hartmut bischoff wrote:
>>
>>
>>
>> On Friday, July 31, 2015 at 10:20:08 PM UTC+2, Chris Whalen wrote:
>>>
>>> I don't disagree. Normally, I would not expect a RDB request to return
>>> this information but due to orientdb's polymorphism capabilities I think it
>>> would be reasonable. As my schema is not static, I cannot rely on a java
>>> object to determine a class' ancestors; new sub classes will be defined
>>> during run time
>>>
>>
>> For this purpose I maintain a »classes-Object« which is updated whenever
>> a class is created or removed. Then there is a method to get the
>> class-hierarchy of the database, based on the object-root
>> https://github.com/topofocus/active-orient/blob/master/lib/rest.rb rows
>> 160-220
>>
>> If you want to go the other way, just define a method 'superClass' for
>> every fetched Object. Then Method.superClass.superClass.(...) reveals the
>> hole tree of the corresponding ruby/java-objects.
>> Realisation in Ruby:
>> https://github.com/topofocus/active-orient/blob/master/lib/model.rb rows
>> 56-60
>>
>>
>>
>>
>
--
---
You received this message because you are subscribed to the Google Groups
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.