Queries on certain relationships return empty
NataliaKo opened this issue · comments
0 down vote favorite
I am completely confused trying to query related nodes. In my models.py I have:
class Person(models.NodeModel):
name = models.StringProperty()
age = models.IntegerProperty()
friends = models.Relationship('self',rel_type='friends_with', related_name = 'friends')
class Pet(models.NodeModel):
name = models.StringProperty()
owner = models.Relationship(Person,
rel_type='owns',
single=True,
related_name='pets', preserve_ordering=True
)
class Place(models.NodeModel):
name = models.StringProperty()
inhab = models.Relationship(Person,
rel_type='lives_in',
single=True,
related_name = 'place', preserve_ordering=True )
loc = models.Relationship('self', rel_type = "has_inhabitants", related_name = 'has_inhab', preserve_ordering=True)
I have created some nodes and relationships.
pete = Person.objects.create(name='Pete', age=30)
garfield = Pet.objects.create()
pete.pets.add(garfield)
pete.save()
pete.pets.all()
[<Pet: Pet object>]
In this case I can successfully view pet-node, related to Pete. Then I created a node for London, where Pete lives, and I want to express the fact that London has Pete as inhabitant:
london = Place.objects.create(name='London')
london.has_inhab.add(pete)
london.save()
Then I try to list what I have just added, and total fail! :
london.has_inhab.all()
[]
At the same time this relationship can be seen in webadmin interface! In graphic mode as well as in shell:
neo4j-sh (London,26)$ ls
==> *name =[London]
==> (me)<-[:<>]-(mydb:Place,5)
==> (me)<-[:has_inhabitants]-(Pete,30)
In your Models, Person has 'friends', not 'pets'.