@@ -109,11 +109,10 @@ Let's implement a tagging system using a many-to-many relationship. This example
109109
110110.. code-block :: python
111111
112- from __future__ import annotations
113112 from sqlalchemy import Column, ForeignKey, Table
114- from sqlalchemy.orm import relationship
115- from sqlalchemy.orm import Mapped, mapped_column
116- from advanced_alchemy.base import BigIntAuditBase, orm_registry, SlugKey
113+ from sqlalchemy.orm import Mapped, mapped_column, relationship
114+ from advanced_alchemy.base import BigIntAuditBase, orm_registry
115+ from advanced_alchemy.mixins import SlugKey
117116 from typing import List
118117
119118 # Association table for post-tag relationship
@@ -144,7 +143,7 @@ Let's implement a tagging system using a many-to-many relationship. This example
144143 """
145144
146145 name: Mapped[str ] = mapped_column(unique = True , index = True )
147- posts: Mapped[List[Post]] = relationship(
146+ posts: Mapped[List[" Post" ]] = relationship(
148147 secondary = post_tag,
149148 back_populates = " tags" ,
150149 viewonly = True
@@ -156,6 +155,7 @@ If we want to interact with the models above, we might use something like the fo
156155.. code-block :: python
157156
158157 from sqlalchemy.ext.asyncio import AsyncSession
158+ from sqlalchemy import select
159159 from advanced_alchemy.utils.text import slugify
160160
161161 async def add_tags_to_post (
@@ -169,7 +169,7 @@ If we want to interact with the models above, we might use something like the fo
169169 )
170170 new_tags = [Tag(name = name, slug = slugify(name)) for name in tag_names if name not in {tag.name for tag in existing_tags}]
171171 post.tags.extend(new_tags + list (existing_tags))
172- db_session.merge(post)
172+ await db_session.merge(post)
173173 await db_session.flush()
174174 return post
175175
@@ -193,10 +193,11 @@ Let's enhance our Tag model with :class:`UniqueMixin`:
193193
194194.. code-block :: python
195195
196- from advanced_alchemy.base import BigIntAuditBase, SlugKey
197- from advanced_alchemy.mixins import UniqueMixin
196+ from advanced_alchemy.base import BigIntAuditBase
197+ from advanced_alchemy.mixins import SlugKey, UniqueMixin
198198 from advanced_alchemy.utils.text import slugify
199199 from sqlalchemy.sql.elements import ColumnElement
200+ from sqlalchemy.orm import Mapped, mapped_column, relationship
200201 from typing import Hashable
201202
202203 class Tag (BigIntAuditBase , SlugKey , UniqueMixin ):
@@ -209,7 +210,7 @@ Let's enhance our Tag model with :class:`UniqueMixin`:
209210 """
210211
211212 name: Mapped[str ] = mapped_column(unique = True , index = True )
212- posts: Mapped[list[Post]] = relationship(
213+ posts: Mapped[list[" Post" ]] = relationship(
213214 secondary = post_tag,
214215 back_populates = " tags" ,
215216 viewonly = True
@@ -250,7 +251,7 @@ We can now take advantage of :meth:`UniqueMixin.as_unique_async` to simplify the
250251 await Tag.as_unique_async(db_session, name = tag_text, slug = slugify(tag_text))
251252 for tag_text in tag_names
252253 ]
253- db_session.merge(post)
254+ await db_session.merge(post)
254255 await db_session.flush()
255256 return post
256257
@@ -282,7 +283,11 @@ Here's an example showing a class to generate a server-side UUID primary key for
282283 class ServerSideUUIDPrimaryKey :
283284 """ UUID Primary Key Field Mixin."""
284285
285- id : Mapped[UUID ] = mapped_column(default = uuid4, primary_key = True , server_default = text(" gen_random_uuid()" ))
286+ id : Mapped[UUID ] = mapped_column(
287+ default = uuid4,
288+ primary_key = True ,
289+ server_default = text(" gen_random_uuid()" ),
290+ )
286291 """ UUID Primary key column."""
287292
288293 # noinspection PyMethodParameters
@@ -293,7 +298,7 @@ Here's an example showing a class to generate a server-side UUID primary key for
293298
294299
295300 class ServerSideUUIDBase (ServerSideUUIDPrimaryKey , CommonTableAttributes , DeclarativeBase ):
296- """ Base for all SQLAlchemy declarative models with the custom UUID primary key ."""
301+ """ Base for all SQLAlchemy declarative models with the custom UUID primary key."""
297302
298303 registry = orm_registry
299304
0 commit comments