orientechnologies / pyorient

OrientDB driver for Python that uses the binary protocol.
Apache License 2.0
119 stars 38 forks source link

Graph always returns elements of type 'Vertex' with OGM #24

Closed FalFire closed 7 years ago

FalFire commented 7 years ago

When querying using the OGM, for instance MyClass.objects.query("").all(), the objects that are returned are always of type Vertex rather than in this case MyClass. I think this is because the method vertex_from_record in ogm/graph.py checks the registry for the value of the property _class on the record, which is not in lowercase while the registry entries are.

TropicalPenguin commented 7 years ago

That would seem to imply that MyClass was not added to the database schema by the OGM but in some other fashion.

i.e., using this will not work if 'MyClass' has already been created with a non-lowercase name:

from pyorient.ogm.declarative import declarative_node

Node = declarative_node()
class MyClass(Node):
    pass

In this case, an element_type (or label, for a relationship) must be provided, so that the correct case will be preserved in the registry for calls to Graph.create_all or Graph.include:

class MyClass(Node):
    element_type = 'MyClass'

As an aside, query() doesn't accept a string, so that example verbatim raises an exception.

Not a bug.

Ostico commented 7 years ago

Close.