sqlalchemy Assoction_proxy滤波器返回阵列(_associationList)

发布于 2025-02-14 00:19:57 字数 1992 浏览 1 评论 0原文

我正在使用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 an
sqlalchemy.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文