coleifer/peewee — Issue #26: Behaviour of __in against foreign keys doesn't behave quite like one might expect
Author: chadcatlett
Created: 2011-12-14 22:25:34+00:00
State: open

Given the following models:

```python

class ModelA(model):
blah = CharField()

class ModelB(model):
modela = ForeignKeyField(ModelA)
blah = CharField()

```

Doing a query like this, gives results not quite expected:

```python

modb = ModelB.get(id=1)
modas = ModelA.select().where(id__in=modb.modela)
```

The second query uses ModelB's primary key, instead of the modela_id column. The above example is sort of useless, as one could just use modb.modela, but when combined with Q():

```python

modb = ModelB.get(id=1)
modas = ModelA.select().where(~Q(id__in=modb.modela))

```

The above would allow one to fetch all ModelA records that aren't related to ModelB.

Changing this would break the current behavior, but in my opinion it would make it behave more like the code actually reads.

What do you think?