You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
... it raises an exception: asyncpg.exceptions.UndefinedTableError: missing FROM-clause entry for table "selfemployed"
Notice: I'm querying Courier model, not Selfemployed.
The resulting query is as follows:
SELECTcouriers.idAS id, ..., vo40c1_users.idAS vo40c1_id, ...
FROM users AS js5485_users, couriers LEFT OUTER JOIN users AS vo40c1_users ONvo40c1_users.id=selfemployed.user_idWHERE (js5485_users.telegram_id= :telegram_id_1) ORDER BYcouriers.id , vo40c1_users.id
Notice this part: ON vo40c1_users.id=selfemployed.user_id. It is trying to filter by a field from Selfemployed model, which isn't even related to the query.
So.. The question is: What have I done wrong?
upd
It seems that the query builder grabs the "tablename" of UserReference on JOIN, and the tablename gets redifined every time you inherit from it to the tablename of child.
If we swap Courier and Selfemployed so that Courier gets defined last, queries are built with couriers.user_id.
Defining UserReference as a Model, as well as adding a tablename to Meta of newly defined Model doesn't help.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
What have I done wrong?
Suppose we have following structure.
Some organization moments:
User model and mixin UserReference referencing a user.
Models that inherit from UserReference
For some reason, when I
... it raises an exception:
asyncpg.exceptions.UndefinedTableError: missing FROM-clause entry for table "selfemployed"
Notice: I'm querying
Courier
model, notSelfemployed
.The resulting query is as follows:
Notice this part:
ON vo40c1_users.id=selfemployed.user_id
. It is trying to filter by a field fromSelfemployed
model, which isn't even related to the query.So.. The question is: What have I done wrong?
upd
It seems that the query builder grabs the "tablename" of
UserReference
onJOIN
, and the tablename gets redifined every time you inherit from it to the tablename of child.If we swap
Courier
andSelfemployed
so thatCourier
gets defined last, queries are built withcouriers.user_id
.Defining UserReference as a
Model
, as well as adding atablename
to Meta of newly definedModel
doesn't help.Possibly a bug?
Beta Was this translation helpful? Give feedback.
All reactions