Classic many-to-many relation
Rather than querying from the perspective of Account (which may have 0..n codes), you should query from the intermediary model and eagerly load the associated account/code:

```python
query = (AccountCode
        .select(AccountCode, Account, Code)
        .join_from(AccountCode, Account)
        .join_from(AccountCode, Code)
        .where(AccountCode.account = account_id))
for acc_code in query:
    # acc_code.account or acc_code.code are already loaded so no more queries
```

For your example to work, peewee would have to de-duplicate data to ensure all the codes were assigned to a single account.
Hello!
I have a strange problem doing classic many-to-many relation join. I use an intermediate table as suggested in official docs for this. I have enabled query log and noticed that despite join query is correct and actually returns everything that I need there are still additional excess queries done. Here are the models I use:

```python
class Account(IModel):
    balance = MoneyField()
    number = IntegerField(null=False)
    name = CharField(max_length=64, null=False)
    type = SmallIntegerField(null=False)
    updated = DateTimeField(null=True)

class Code(IModel):
    type = SmallIntegerField(null=False)
    code = CharField(max_length=25, null=False)
    description = CharField(max_length=100, null=False)
    parent_code = ForeignKeyField('self', default=0)

class AccountCode(IModel):
    code = ForeignKeyField(Code, null=False)
    account = ForeignKeyField(Account, backref='codes', null=False)
    balance = MoneyField()
```

And this is the query:

```python
acc = (Account
        .select(Account, AccountCode, Code)
        .join(AccountCode)
        .join(Code)
        .where(Account.id == account_id))
for acc_code in acc[0].codes:
        # do something with acc_code and acc_code.code
```

And here is the query log:
```sql
('SELECT `t1`.`id`, `t1`.`balance`, `t1`.`number`, `t1`.`name`, `t1`.`type`, `t1`.`updated`, `t2`.`id`, `t2`.`code_id`, `t2`.`account_id`, `t2`.`balance`, `t3`.`id`, `t3`.`type`, `t3`.`code`, `t3`.`description`, `t3`.`parent_code_id` FROM `account` AS `t1` INNER JOIN `account_code` AS `t2` ON (`t1`.`id` = `t2`.`account_id`) INNER JOIN `code` AS `t3` ON (`t3`.`id` = `t2`.`code_id`) WHERE (`t1`.`id` = %s)', [1])
('SELECT `t1`.`id`, `t1`.`code_id`, `t1`.`account_id`, `t1`.`balance` FROM `account_code` AS `t1` WHERE (`t1`.`account_id` = %s)', [1])
('SELECT `t1`.`id`, `t1`.`type`, `t1`.`code`, `t1`.`description`, `t1`.`parent_code_id` FROM `code` AS `t1` WHERE (`t1`.`id` = %s) LIMIT %s OFFSET %s', [9420, 1, 0])
('SELECT `t1`.`id`, `t1`.`type`, `t1`.`code`, `t1`.`description`, `t1`.`parent_code_id` FROM `code` AS `t1` WHERE (`t1`.`id` = %s) LIMIT %s OFFSET %s', [9423, 1, 0])
```

As you can see there are 3 additional excess queries done which really shouldn't happen in case of join (afaik).