Many to many relationship within itself
and throw in an .aggregate_rows() at the end, though i'm not sure how it'd respond with so many joins.
 @Thomaxo -- what you want is to probably use a combination of model aliases and explicit join predicates.

First off, it might make better sense to query the "B" table (the junction table). For example:

``` python
A2 = A.alias()
C2 = C.alias()
query = (B
         .select(B, A, A2, C, C2)
         .join(A, on=(B.original_A == A.id))
         .join(C, on=(A.c == C.id))
         .switch(B)
         .join(A2, on=(B.related_A == A2.id).alias('related_A'))
         .join(C2, on=(A2.c == C2.id).alias('c')))

for b in query:
    print b.original_A, b.original_A.c
    print b.related_A, b.related_A.c
```
 If you believe you've found an issue with Peewee, please open an issue. Otherwise, if you're still stuck, I'd suggest the mailing list or stackoverflow.
 Thanks for the help! :)

Not sure if this is an issue rather than a question, but here it goes..

Given a model A, and  a model B (a many to many table)

``` python
class B(Model):

    original_A = ForeignKeyField(
        A,
        related_name='AB'
    )
    related_A = ForeignKeyField( 
        A,
        related_name='BA'
    )

    class Meta:
        database = db
```

The 2 foreign keys, as you can see, relate to the same model.
The tricky part gets when you try to query it,

The query is: (C is something relating to A)

``` python
query = models.A.select(
                A,
                B,
                C
            ).join(
                models.C
            ).switch(            ##
                models.A
            ).join(
                models.B
            ).join(
                models.A
            ).join(
                models.C
            )
```

So, how can i get rid of the ambiguity and say that the first join of A with model B neets to relate to the first column of B, and the second join of B with A needs to relate to the second column of B?

In the end what i want to get is:

``` python
for a in query:
    #do something with a
    for c in a:
        #do something with its related c
    for b in a:
        for ba in b:
            #do something with its relations with itself
            for c in ba:
                #do something with its related c of its related self..
```

kind regards,
Thomas
