sqlalchemy Assoction_proxy滤波器返回阵列(_associationList)
我正在使用Association_proxy
这样的:
study_participantions = association_proxy("quests", "study_participant",creator=lambda sp: sp.questionnaire)
我是我的数据库,我有这些表:
detter> detter>
studyparticipant
问卷
<
<代码>患者和问卷
与多对一的关系链接。
问卷
可以通过一对一的关系是AA Studyparticaint
的一部分。
studyparticipant
和患者
没有直接链接,因为studyparticaint
可以是匿名的。
因此,通过getter和setter,我可以查询患者
调查表。
由于我正在使用现有的代码库,因此我必须将患者保留在问卷中,
studyparticipant
可以通过患者
的代理找到。获取和设置有效,但是如果问卷
不是studyparticipant
返回的数组包含none
值是否有可能过滤它们,所以我会得到一个干净的阵列吗?可以肯定的仍然应该是 sqlalchemy.ext.sassociationproxy._associationList
因此,将其附加和删除仍然可行。
简化类:
class Patient(Model):
__tablename__ = 'patient'
id = Column(Integer, primary_key=True)
study_participantions = association_proxy("quests", "study_participant",creator=lambda sp: sp.questionnaire)
class StudyParticipant(Model): #better name would be participation
__tablename__ = "study_participant"
id = Column(Integer, primary_key=True)
pseudonym = Column(String(40), nullable = True)
questionnaire = relationship("Questionnaire", backref="study_participant",uselist=False) # why go via the StudyQuestionnaire
class Questionnaire(Model, metaclass=QuestionnaireMeta):
__tablename__ = 'questionnaire'
id = Column(Integer, primary_key=True)
patient_id = Column(Integer(), ForeignKey('patient.id'), nullable=True)
patient = relationship('Patient', backref='quests',
primaryjoin=questionnaire_patient_join)
I'm using an association_proxy
like this:
study_participantions = association_proxy("quests", "study_participant",creator=lambda sp: sp.questionnaire)
I my database, I have these tables:
Patient
StudyParticipant
Questionnaire
Patient
and Questionnaire
are linked with a many-to-one relationship.
A Questionnaire
can be part of aa StudyParticipant
via a one-to-one relationship.
StudyParticipant
and Patient
are not directly linked since StudyParticipant
can be anonymous.
So via getter and setter, I can query the Patient
trough the questionnaire.
Since I'm working with an existing codebase, I have to keep the patient inside the questionnaire
The StudyParticipant
can be find via the proxy from the Patient
. Getting and setting works but if the Questionnaire
is not part of a StudyParticipant
the returned array contains None
values is it possible to filter them out so i would get a clean array? For sure it should still be ansqlalchemy.ext.associationproxy._AssociationList
so appending and removing to it would still work.
Simplified classes:
class Patient(Model):
__tablename__ = 'patient'
id = Column(Integer, primary_key=True)
study_participantions = association_proxy("quests", "study_participant",creator=lambda sp: sp.questionnaire)
class StudyParticipant(Model): #better name would be participation
__tablename__ = "study_participant"
id = Column(Integer, primary_key=True)
pseudonym = Column(String(40), nullable = True)
questionnaire = relationship("Questionnaire", backref="study_participant",uselist=False) # why go via the StudyQuestionnaire
class Questionnaire(Model, metaclass=QuestionnaireMeta):
__tablename__ = 'questionnaire'
id = Column(Integer, primary_key=True)
patient_id = Column(Integer(), ForeignKey('patient.id'), nullable=True)
patient = relationship('Patient', backref='quests',
primaryjoin=questionnaire_patient_join)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论