Join by field (using)
Joining on a subquery is totally easy in peewee, you just have to use the explicit form of the join predicate:

``` python
subq = Service.select(fn.unnest(Service.ms).alias('code'))
subq = subq.alias('svc')  # Subqueries need an alias.
qs = (MedServ
      .select(MedServ.code, MedServ.name)
      .join(subq, on=(MedServ.code == subq.c.code)))
```

To access a column inside the subquery we use the magical "subq.c.code". The ".c" just allows us to create references to values inside the subquery.

Does that help?

And no, peewee itself will not, but there are already at least one Peewee extension that provide asyncio. This one seems pretty popular:

https://github.com/05bit/peewee-async
 Also, docs: http://docs.peewee-orm.com/en/latest/peewee/querying.html#using-subqueries
 > Does that help?

Yes, that's I need! Thanks!
Really, yesterday I tired and forgot about `.c`

I surprised about progress peewee-asyncio. Last time I saw the project it had 0.0.5 version :)
What is the main difference between 2.8 and 3 branches of peewee?
 Closing as the issue seems resolved.

Differences: mostly around the SQL generation, but generally the goal is to have a more powerful sql generator. Also decoupling the returning of records from model instances

I try to write query:

``` sql
select code, name
    from medservices join (
        select unnest(ms) as code from services where id = 7
    ) u using (code);
```

in peewee. And I can't understand how to do:

``` python
    qs = (MedServ
        .select(MedServ.code, MedServ.name)
        .join(
            Service.select(fn.unnest(Service.ms).alias('code')).where(Service.id == id),
            on=(MedServ.code == ???))
```

I need join table with subquery by named field. Is it possible?

P.S. Will the 3'd version of peewee use asyncio? :-)
