Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queries on certain relationships return empty #245

Open
NataliaKo opened this issue May 13, 2014 · 1 comment
Open

Queries on certain relationships return empty #245

NataliaKo opened this issue May 13, 2014 · 1 comment

Comments

@NataliaKo
Copy link

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)

@bibby
Copy link

bibby commented Aug 16, 2014

In your Models, Person has 'friends', not 'pets'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants