orientechnologies / pyorient

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

Select Link fields in OGM queries #26

Closed golfarelli closed 7 years ago

golfarelli commented 7 years ago

Hi, I'm still learning the driver and testing ogm queries before starting to use it in my application. I've created some Node classes and now I would select some properties through Link field.

This is my code

SchemaNode = declarative.declarative_node()
SchemaRelationship = declarative.declarative_relationship()

class Role(SchemaNode):
    element_plural = 'roles'
    element_type = 'Role'
    name = String()

class User(SchemaNode):
    element_plural = 'users'
    element_type = 'User'
    first_name = String()
    last_name = String()
    email = String()
    role = Link(linked_to=Role)
    active = Boolean()

graph = Graph(Config.from_url('DB', 'root', 'pwd', initial_drop=False))
graph.include(SchemaNode.registry)

query = graph.users.query().what(User.first_name, User.role.name).filter_by(first_name='Fabio')
for u in query:
    print(u)

graph.client.db_close()

But the result is

User_props(first_name='Fabio', None_=None)

How can I select the link fields ? Is there any documentation on ogm queries ?

Thanks in advance

Ostico commented 7 years ago

Hi @golfarelli , please post this question ( or link it ) in the main repository ( this is the OFFICIAL one but it is a mirror ) and address the request to @TropicalPenguin , he is the main contributor for the OGM part.