相关疑难解决方法(0)

如何查询多对多关系中的空记录

class BlogPost(SchemaBase):
  id = Column(Integer, primary_key=True)
  name    = Column(String,  unique=True)
  authors = relationship('Authors', secondary='authors_to_blog_post')
  __tablename__ = 'blogpost'

class Authors(SchemaBase):
  id = Column(Integer, primary_key=True)
  name    = Column(String,  unique=True)
  __tablename__ = 'author'

authors_to_blog_post = Table('authors_to_blog_post', Base.metadata,
    Column('author_id', Integer, ForeignKey('author.id')),
    Column('blogpost_id', Integer, ForeignKey('blogpost.id'))
    )
Run Code Online (Sandbox Code Playgroud)

现在如何查询没有任何作者的所有博文? session.query(BlogPost).filter(BlogPost.authors == [])不起作用

python sql many-to-many sqlalchemy

2
推荐指数
1
解决办法
2037
查看次数

标签 统计

many-to-many ×1

python ×1

sql ×1

sqlalchemy ×1