我是石墨烯的新手
我正在尝试从 3 个模型接收信息:两个模型连接(用户和类)具有多对多关系,一个模型(课程)与类模型多对一连接。
我的目标是有可能在用户数据之后将有关 Class 模型的信息显示为 Class 内的列表。但我只能显示数据 beetwen 用户和类。但需要列出所有数据用户 -> 课程 -> 课程。冷了怎么办?
这里它必须看起来
我的模型是:
table = Table('table', Base.metadata,
Column('left', Integer, ForeignKey('left.id')),
Column('right', Integer, ForeignKey('right.id'))
)
class User(Base):
__tablename__ = 'right'
id = Column(Integer, primary_key=True)
name = Column(String(255))
lessons = relationship("Class",
secondary=table,
backref="user")
class Classes(Base):
__tablename__ = 'left'
id = Column(Integer, primary_key=True)
name = Column(String(255))
lessons = relationship('User', backref='classes')
class Lessons(Base):
__tablename__ = 'lessons'
id = Column(Integer, primary_key=True)
name = Column(String(255))
class_id= Column(Integer, ForeignKey('class.id'))
我的模式和查询是:
class UserSchema(SQLAlchemyObjectType):
class Meta:
model = User
interfaces = (relay.Node, )
class ClassesSchema(SQLAlchemyObjectType):
class Meta:
model = Contract
interfaces = (relay.Node, )
class LessonsSchema(SQLAlchemyObjectType):
class Meta:
model = Plan
interfaces = (relay.Node,)
class Query(graphene.ObjectType):
node = relay.Node.Field()
# Allows sorting over multiple columns, by default over the primary key
all = SQLAlchemyConnectionField(UserSchema)
# Disable sorting over this field
all_classes = SQLAlchemyConnectionField(ClassesSchema)
all_lessons = SQLAlchemyConnectionField(LessonsSchema)
schema = graphene.Schema(query=Query)
输出割草是:
{
"data": {
"all": {
"edges": [
{
"node": {
"id": "TWFpbmNoZW1hOjE=",
"name": "User 1",
"Classes": {
"edges": [
{
"node": {
"id": "Q29udHJhY3RTY2hlbWE6Mg==",
"name": "First class",
"lessons": {
"edges": []
}
}
}
]
}
}
},
主要问题是课程列表是空的,但是如果我查询课程它会显示信息,并且它不是空的。