is required in this case so that the :func:`.attribute_keyed_dict`
may be appropriately parametrized::
+ from typing import Dict
from typing import Optional
from sqlalchemy import ForeignKey
id: Mapped[int] = mapped_column(primary_key=True)
- notes: Mapped[dict[str, "Note"]] = relationship(
+ notes: Mapped[Dict[str, "Note"]] = relationship(
collection_class=attribute_keyed_dict("keyword"),
cascade="all, delete-orphan",
)
id: Mapped[int] = mapped_column(primary_key=True)
- notes: Mapped[dict[str, "Note"]] = relationship(
+ notes: Mapped[Dict[str, "Note"]] = relationship(
collection_class=attribute_keyed_dict("note_key"),
back_populates="item",
cascade="all, delete-orphan",
id: Mapped[int] = mapped_column(primary_key=True)
- notes: Mapped[dict[str, "Note"]] = relationship(
+ notes: Mapped[Dict[str, "Note"]] = relationship(
collection_class=column_keyed_dict(Note.__table__.c.keyword),
cascade="all, delete-orphan",
)
id: Mapped[int] = mapped_column(primary_key=True)
- notes: Mapped[dict[str, "Note"]] = relationship(
+ notes: Mapped[Dict[str, "Note"]] = relationship(
collection_class=mapped_collection(lambda note: note.text[0:10]),
cascade="all, delete-orphan",
)
id: Mapped[int] = mapped_column(primary_key=True)
- bs: Mapped[dict[str, "B"]] = relationship(
+ bs: Mapped[Dict[str, "B"]] = relationship(
collection_class=attribute_keyed_dict("data"),
back_populates="a",
)
when new elements are added to the dictionary::
from __future__ import annotations
+ from typing import Dict
from sqlalchemy import ForeignKey
from sqlalchemy import String
# user/user_keyword_associations relationship, mapping
# user_keyword_associations with a dictionary against "special_key" as key.
- user_keyword_associations: Mapped[dict[str, UserKeywordAssociation]] = relationship(
+ user_keyword_associations: Mapped[Dict[str, UserKeywordAssociation]] = relationship(
back_populates="user",
collection_class=attribute_keyed_dict("special_key"),
cascade="all, delete-orphan",
# proxy to 'user_keyword_associations', instantiating
# UserKeywordAssociation assigning the new key to 'special_key',
# values to 'keyword'.
- keywords: AssociationProxy[dict[str, Keyword]] = association_proxy(
+ keywords: AssociationProxy[Dict[str, Keyword]] = association_proxy(
"user_keyword_associations",
"keyword",
creator=lambda k, v: UserKeywordAssociation(special_key=k, keyword=v),
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(64))
- user_keyword_associations: Mapped[dict[str, UserKeywordAssociation]] = relationship(
+ user_keyword_associations: Mapped[Dict[str, UserKeywordAssociation]] = relationship(
back_populates="user",
collection_class=attribute_keyed_dict("special_key"),
cascade="all, delete-orphan",
)
# the same 'user_keyword_associations'->'keyword' proxy as in
# the basic dictionary example.
- keywords: AssociationProxy[dict[str, str]] = association_proxy(
+ keywords: AssociationProxy[Dict[str, str]] = association_proxy(
"user_keyword_associations",
"keyword",
creator=lambda k, v: UserKeywordAssociation(special_key=k, keyword=v),
# 'keyword' is changed to be a proxy to the
# 'keyword' attribute of 'Keyword'
- keyword: AssociationProxy[dict[str, str]] = association_proxy("kw", "keyword")
+ keyword: AssociationProxy[Dict[str, str]] = association_proxy("kw", "keyword")
class Keyword(Base):