Python 从SQLAlchemy中的M:N关系获取所有值
我将sqlalchemy中的M:N关系定义为:Python 从SQLAlchemy中的M:N关系获取所有值,python,python-3.x,sqlalchemy,marshmallow-sqlalchemy,Python,Python 3.x,Sqlalchemy,Marshmallow Sqlalchemy,我将sqlalchemy中的M:N关系定义为: association_table = Table('association_table', base.metadata, Column('content_id', UUID(as_uuid=True), ForeignKey('content.content.content_id'), primary_key=True),
association_table = Table('association_table', base.metadata,
Column('content_id', UUID(as_uuid=True),
ForeignKey('content.content.content_id'), primary_key=True),
Column('message_id', UUID(as_uuid=True), ForeignKey('messages.webhooks.message_id'), primary_key=True),
schema='content'
)
class Messsages(base):
__table_args__ = {"schema": "messages"}
__tablename__ = 'webhooks'
id = Column('message_id', UUID(as_uuid=True), primary_key=True)
parents = relationship(
"Content",
secondary=association_table,
back_populates="children", uselist=False)
class Content(base):
__tablename__ = "content"
__table_args__ = {"schema": "content"}
id = Column("content_id", UUID(as_uuid=True), primary_key=True)
children = relationship(
Messsages,
secondary=association_table,
uselist=False,
back_populates="parents")
class ContentRepository:
def __init__(self, session):
def get_all(self):
return self.session.query(Content).all()
for config in ContentRepository(session).get_all():
ids = config.children.id
我在ids中只得到一个值,表中有多行,但它只返回一个值