neomodel
neomodel copied to clipboard
Using order_by with Relationship Properties
I see in the documentation that I can use obj.rel.order_by('prop_name') to order the relatives by the given node property. But what if I want to order by a relation property? Something like this:
class OrderedRel(StructuredRel):
order = IntegerProperty(required=True)
class Item(StructuredNode):
...
class NodeSequence(StructuredNode):
item = RelationTo('Item', 'ITEM', model=OrderedRel)
for item in node_sequence.item.order_rel_by('order'):
...
Great idea.. yea its definitely missing.
Then? Any solution?
Waiting for this.
Yes, this would be really helpful. Only workaround is loading all objects and then finding the according relationships with model1.relationship_name.relationship(model2). After that I can retrieve the relationship properties and sort the objects accordingly. I'm sure this can be done much faster natively inside neo4j though.
Actually a second variant would be to just model the relationship as a node and add the properties to that node. Then on both sides add Relationships to the original models with cardinality 1.
That would result in: map(lambda x: x.model2 , model1.relationship.order_by('property'))
I maked a class that parametrize the 'order by some relation property' and then used the cipher to make/execute the query. After that i inflated the values (the result nodes) and it worked.
Any update on this? I was hoping to encode an "active" attribute in a relationship and use that to filter my queries. I will try the suggestions above.