On 13 Mai, 22:23, Austin Gabel <
aga...@gmail.com> wrote:
> I am trying to use the ORM to build the following query:
> """SELECT * FROM category AS node, category AS parent WHERE node.lft BETWEEN
> parent.lft AND parent.rgt"""
>
> I am attempting to create the table aliases using .extra() but I'm having a
> bit of difficulty. I have left out the where statements in order to reduce
> complexity while troubleshooting this issue. My current code looks like
> this.
> category_list = Category.objects.all().extra(tables=['category'])
>
> The way I understand the documentation [1] is if a table is listed in the
> tables argument that already exists in the query, it will add the table with
> a generic alias. However, it is simply ignoring the additional table. This
> is the SQL that is produces.
>
> ('SELECT "category"."id", "category"."lft", "category"."rgt",
> "category"."tree_id", "category"."depth", "category"."name" FROM "category"
> ORDER BY "category"."name" ASC', ())
>
> Is this not the correct way to go about adding a table alias? Am I just
> missing something or am I way off track here?
>