#19222: Documentation for use_for_related_fields should clarify that it doesn't
work for intermediate joins
-------------------------------+--------------------------------------
Reporter: andrewbadr | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 1.4
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by jedediah):
{{{
class BagelManager(Manager):
use_for_related_fields = True
def get_query_set(self):
return super(BagelManager,
self).get_query_set().filter(deleted=False)
class Bagel(Model):
deleted = BooleanField()
objects = BagelManager()
all_bagels = Manager()
def __str__(self):
return "deleted" if self.deleted else "active"
class Customer(Model):
bagels = ManyToManyField(Bagel)
}}}
{{{
>>> Bagel.objects.create(deleted=False)
<Bagel: active>
>>> Bagel.objects.create(deleted=True)
<Bagel: deleted>
>>> Bagel.all_bagels.all()
[<Bagel: active>, <Bagel: deleted>]
>>> Bagel.objects.all()
[<Bagel: active>]
>>> Bagel.objects.filter(deleted=True)
[]
}}}
Correct so far... deleted bagel is invisible through default manager
{{{
>>> c = Customer.objects.create()
>>> c.bagels.add(*Bagel.all_bagels.all())
>>> c.bagels.all()
[<Bagel: active>]
>>> c.bagels.filter(deleted=True)
[]
}}}
Still good... deleted bagel is invisible to related fields
{{{
>>> Customer.objects.filter(bagels__deleted=True)
[<Customer: Customer object>]
}}}
Here's the problem. The query join sees the deleted bagel. I would expect
queries through relations to see the same data as the relations
themselves.
This should either be fixed or documented as a known limitation.
--
Ticket URL: <https://code.djangoproject.com/ticket/19222#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.3b69d8ef530a44139f715bb77c0d783f%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.