On Fri, Jul 4, 2014 at 2:54 PM, Javier Guerra Giraldez
<
jav...@guerrag.com> wrote:
> what purpose does the "container__item__previous__isnull=True"
> argument serve here?
To filter on the initial item in the list. I'm looking for flag=True
*only* on the first item in the list. flag=True could be set on other
items in the same chain, but I don't care about those. The goal of the
query is:
I'm looking for all *current* items such that the *first item* in the
chain has *flag = true*.
In raw SQL I want the query to be:
SELECT myapp_item.*
FROM "myapp_item"
INNER JOIN "myapp_container"
ON ( "myapp_item"."container_id" = "myapp_container"."id" )
INNER JOIN "myapp_item" T3
ON ( "myapp_container"."id" = T3."container_id" )
WHERE ("myapp_item"."current" = True AND T3."previous_id" IS NULL AND
T3."flag" = True )
So the WHERE condition flag=True, only applies to the initial item.
>i think it means "an item that belongs to a container that has an item with no 'previous'"
Correct, but not just any container, but the same container as the
item being filtered.
> which if it's a linked list, then any non-empty container would comply
Right, except then the "container__item__flag=True" should influence it further.
> and since you start the query from the item, then the container is non-empty by definition.
Yes, correct.
> btw, a linked list in a database? can you elaborate on that idea?
It is just one way to think about it. It is not really a linked list.
I simply meant the items are linked together by the "previous" point.
In my actual application item represent a step with history (previous
being that history). Container represents the process of the step (has
actual fields). So each step has a previous step in the process.
Sometimes I want to query for the current step in the process based on
the initial step.
Cheers,
Jon