2

I'm not sure why I get this warning; it might well be that I do not completely comprehend the related_name concept, but I thought having different rel_types would make the above model not ambiguous/conflicting...

I get the following warnings in neo4django:

>>> from evidences.models import *
/[...]/neo4django/db/models/relationships.py:180: UserWarning: `evidence` and `evidence` share a relationship type and direction. Is this what you meant to do?
  % (r.name, name))
/[...]/neo4django/db/models/relationships.py:180: UserWarning: `families` and `families` share a relationship type and direction. Is this what you meant to do?
  % (r.name, name))

The related model can be found here: https://gist.github.com/szabi/e57f23d76b885d604a36

I think that neither relationship type nor target model is shared between the relationships with the same related_name.

Using Django 1.4, neo4django current from git.

Any ideas?

A Sz
  • 984
  • 7
  • 19

1 Answers1

3

There's definitely a conflict between

spouses = models.Relationship('Person',rel_type='SPOUSE',related_name='families')

and

children = models.Relationship('Person',rel_type='CHILD',related_name='families')

Setting related_name signifies that you want model instances on the other end of the relationship to be accessed by that name. Since both lines are pointing to Person, every Person instance would need to somehow figure out if the families relationship field refers to rels of type 'SPOUSE' or 'CHILD'.

I'm not sure about the evidence warning, though. If the models are working how you expect, I wouldn't worry about it.

Matt Luongo
  • 14,371
  • 6
  • 53
  • 64
  • Ha! I checked the `evidence` warning, saw no conflict and did not care to check `families`! Will you set up a unit test looking into the `evidence` case? – A Sz May 28 '13 at 05:30
  • So, what I'd like is to have in Person an object `families` which is basically a *union* of incoming SPOUSE and CHILD (the other end of the Relationship being always instances of `Family`). How do I achieve this? Would creating an own **Manager** be the right way? Actually, I'll need to have p.families.all() giving all families, and differentiating in the add function: p.families.addAsChildFam(..) vs. p.families.addAsSpouseFam(..), as .add on such a "union" manager is underspecified. – A Sz May 28 '13 at 05:38
  • If you'd do me a favor and raise an issue, I can try to look further into the evidence case. Heck, if you're feeling generous I'm happy to accept pulls, especially confirming bugs :) I have a similar, kind of strange relationship use case- let me look at my solution and see if it's generalizable. A customer `Manager` will probably be a part of it, but I have a feeling this will be pretty involved regardless. Hopefully I'll have a gist for you soon. – Matt Luongo May 28 '13 at 14:56
  • Issue raised. While I appreciate the gentle hint re pull I'm pretty new to github (while used git on very small-scaled single person projects), so I'm way to new and thus yet anxious using all its great community features. Actually, I'm not even sure I get the lingo correctly. Did you propose me pulling neo4django, fixing it and sending a pull request (this is really out of scope right now) or did you propose me to post the project stub in a repo you could pull as a "testcase" or to confirm bugs? Btw, is there a slightly more private way to get in touch with you, Matt? – A Sz May 28 '13 at 16:31
  • Thank you sir. I was suggesting you add a test case directly to the project, but no worries if you aren't comfortable. Briefly, if you hit "fork" on the repo, you'll have your own private version which you can `git clone`, commit any changes you'd like, and `git push` to. In GitHub, you issue a pull request through their interface after you push to your fork, asking the original maintainer to merge your changes in. – Matt Luongo May 28 '13 at 16:35
  • I've just posted a possible solution to the family modeling problem - https://gist.github.com/mhluongo/5664051 . It's very not-supported / uses non-public methods in neo4django, but it let's you add families to a person like `person.children_families.add(fam)` or `person.spouse_families.add(fam)`, and pull all families with `person.families.all()`. As to getting in touch more privately, I tweet @mhluongo or you can shoot me an email at mhluongo - at - gmail. – Matt Luongo May 28 '13 at 16:38