-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Genarated query problem #913
Comments
Please fix the formatting of code. |
Sorry, i've updated code formatting. |
To fix this I believe if you explicitly select the Video ID column you'll be set: video = Video.select(Video.id).where(Video.name == 'v5.mp4')
query = Relationship.delete().where(Relationship.video == video)
print query Outputs: DELETE FROM "relationship"
WHERE ("video_id" = (
SELECT "t1"."id"
FROM "video" AS t1
WHERE ("t1"."name" = ?)
ORDER BY "t1"."add_date" DESC
)) If you've already got the query from somewhere else and want to modify the SELECT clause, you can do: query = Relationship.delete().where(Relationship.video == video.select(Video.id)) An unrelated suggestion: Never ever ever specify a default ordering for your models. It's a code smell and I regret building it into Peewee's API (the idea comes from Django originally, and the Django community seems to feel the same way about it). If you want a default ordering that's easily accessible, just do something like: class Video(BaseModel):
# ... fields ...
@classmethod
def all(cls):
return cls.select().order_by(cls.add_date.desc())
# ------ elsewhere in your code ------ #
videos = Video.all() |
I do deleted query on Relationship table
query = Relationship.delete().where(Relationship.video == video)
<class 'libs.basemodel.Relationship'> DELETE FROM "relationship" WHERE ("video_id" = (SELECT "t2"."id" FROM "video" AS t1 WHERE ("t1"."name" = ?) ORDER BY "t1"."add_date" DESC)) [u'v5.mp4']
Problem:
OperationalError: no such column: t2.id
My models very simple:
The text was updated successfully, but these errors were encountered: