On Wed, 2007-10-31 at 08:38 +1030, Darryl Ross wrote:
> Kevin wrote:
> 
> > models.TestLine.objects.filter(dimm__size=1024).filter(dimm__size=2048)
> > 
> > This returns an empty set, but I know there is a test with multiple
> > dimm objects and meets this criteria. Is there a limitation that I'm
> > missing here? Is there an alternative method to accomplish the intent
> > here?
> 
> It returns an empty set because after the first filter you only have the
> objects with size=1024, then you are asking to filter out of that set
> the ones with size=2048. In SQL it would like like "WHERE size = 1024
> AND size = 2048".
> 
> How about something like:
> 
> models.TestLine.objects.filter(dimm__size__in=[1024, 2048])

Intuitively, each filter() further reduces the results set. So for
many-to-many relations, it makes sense that you can filter on the same
attribute more than once and it should work: since there are multiple
values for that attribute. That's why the current behaviour is a bug and
we're fixing it.

Your workaround only finds TestLines that have size of 1024 or 2048,
without requiring both to exist for the same TestLine. So it's a
superset of what is required.

Regards,
Malcolm

-- 
A clear conscience is usually the sign of a bad memory. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to