谁能解释这两个想法的概念,以及它们与表之间的关系如何?我似乎真的找不到任何能清楚解释它的内容,并且文档觉得简单概念中的术语太多了。例如,在文档中的一对多关系示例中:
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
children = relationship("Child", back_populates="parent")
class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('parent.id'))
parent = relationship("Parent", back_populates="children")
Run Code Online (Sandbox Code Playgroud)
为什么relationship()
进入父类而ForeignKey
进入子类?back_populates
彼此之间到底有什么作用?relationship()
函数在哪个类中是否存在?
假设我有一个列表,例如:
listofpeople = [{'Jack': ['Blue', 'Red', 'Green']}, {'Barry': ['Red', 'Green', 'Orange']}]
Run Code Online (Sandbox Code Playgroud)
如果我要搜索 'Jack' 的索引,如果 'Jack' 是列表中字典的键值,我将如何找到他的索引?