Skip to content

how can i apply filter on related column when using update method #1157

Answered by dantownsend
keinagae asked this question in Q&A
Discussion options

You must be logged in to vote

Here's an example you can run in piccolo playground run:

await Band.update({Band.popularity: Band.popularity + 5}).where(Band.manager.name == 'Guido')

Which is for the following schema:

from piccolo.table import Table
from piccolo.columns import ForeignKey, Integer, Varchar


class Manager(Table):
    name = Varchar(length=100)


class Band(Table):
    name = Varchar(length=100)
    manager = ForeignKey(references=Manager)
    popularity = Integer()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dantownsend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants