Skip to content

Clarification on conditional updates of sub-attributes #28

@sarflux

Description

@sarflux

would there be an easy way to update attributes based on conditions on the sub attributes?

For example if my Dyntastic object looks like so

class Foo(Dyntastic):
    __table_name__ = getenv("TABLE_NAME", None)
    __hash_key__ = getenv("PARTITION_KEY", None)
    pk: str= Field()
    data: Data | None = Field(None)

class Data(BaseModel):
    id: str| None = Field(None)

and I would like to update my data field with some arbitrary condition on my data.id field:

foo = Foo(pk="some_pk")
data_dump = Data(id="bar")
foo.update(A.data.set(data_dump), condition = (A.data.not_exists() | A.data.id.ne("foo") ) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions