scholrly / neo4django

Drop-in Neo4j/Django integration.
GNU General Public License v3.0
358 stars 83 forks source link

Asymmetric relationship saves #89

Open wcbeard opened 12 years ago

wcbeard commented 12 years ago

For related models Choice and Polls, where a poll has multiple choices, creating multiple choices, setting their poll and saving the single poll does not save them to database. (you have to manually save each choice)

>>> p = Poll(question="Who's the first best?", pub_date=timezone.now())
>>> c  = Choice(choice='Chris', votes=1000)
>>> c1 = Choice(choice='Matt', votes=1)
>>> c2 = Choice(choice='Corbin', votes=-1)
>>> c.poll = p
>>> c1.poll = p
>>> c2.poll = p
>>> list(p.choices.all())
[]
>>> p.save()
>>> list(p.choices.all())
[]
>>> c.save()
>>> list(p.choices.all())
[<Choice: Chris>]
*logout/log in*
>>> list(p.choices.all())
[<Choice: Chris>]

Logging out and back in doesn't change anything, so it's not a cache issue.

This is supposed to replicate the Poll and Choice models from the Django tutorial. The model definitions are here.

mhluongo commented 12 years ago

@d10genes, you might want to mention in these issues that you're trying to replicate the tutorial functionality, and include the model definition- otherwise they lack some important context. Great bugfinding otherwise :)

mhluongo commented 12 years ago

Ha, this has turned out to be a bunch more work than I thought- apparently we don't have any sort of relationship updates on the other side of the relationship until an object is saved. I almost have it figured out.

mhluongo commented 12 years ago

Doubling back. What you're trying to do here isn't actually supported in the Django ORM- the tutorial is trying to do this with saved objects, not unsaved. I started to run into some ridiculous cache issues and realized supporting fully un-saved queryset updates would be going above and beyond for most ORMs. Would it make sense for us? Maybe, but we want a drop-in integration, not a new layer for devs to learn. Changing to "needsthought"- I'll circle back and reevaluate next release.