I'm not good at data structures but as I understand the main inner limitation for self-joins is alias_map dict
{
<class 'application.users.models.Price'>: 't1',
<class 'application.users.models.PriceRelation'>: 't2'
}
The same table == the same key. This blocks the very possibility of granting 2 different aliases to single table.
I can only propose to flip this structure:
{
't1': <class 'application.users.models.Price'>,
't2': <class 'application.users.models.PriceRelation'>,
}
Then, I think, Model class should supports alias() method, returning unique object to differ.
t2 = Item.alias('t2')
Item.select(Item, t2).join(t2, on=t2.parent).where(t2.name == 'foo')
Maybe I don't understand quite well the meaning of alias term in Peewee, but I'd come with something like that.