views:

40

answers:

1

Hello,

I get errors when I try to create tables one to one relation. Screen contains crm and crm contains more classes. The relation is one to one between crm, so I want to use the screen id as primary key in crm. And the relation is one to one between crm and some classes, I just added one class as example, so children of crm must contain a screen id as a primary key. When I try to make the last relation, it's when it breaks. I tried to use both, crm id and screen id.

I didn't work. I get errors such as, "UnmappedClassError" when I try to use crm id in ContactInformation, and "Could not determine join condition between parent/child tables on relationship CRM.contactInformation. Specify a 'primaryjoin' expression. If this is a many-to-many relationship, 'secondaryjoin' is needed as well" when I try to use screen id in ContactInformation.

These are my classes:

   class Screen(rdb.Model):
        """Set up screens table in the database"""
        rdb.metadata(metadata)
        rdb.tablename("screens")

        id = Column("id", Integer, primary_key=True)
        title = Column("title", String(100))
        ....

        crm = relationship("CRM", uselist=False, backref="screens")

class CRM(rdb.Model):
    """Set up crm table in the database"""
    rdb.metadata(metadata)
    rdb.tablename("crms")

    id = Column("id", Integer, ForeignKey("screens.id"), primary_key=True)

    contactInformation = relationship("crm_contact_informations", uselist=False, backref="crms")
        ....

class CRMContactInformation(rdb.Model):
    """Set up crm contact information table in the database"""
    rdb.metadata(metadata)
    rdb.tablename("crm_contact_informations")

    **id = Column("id", Integer, ForeignKey("screens.id"), primary_key=True)**
    owner = Column("owner", String(50))
       ...
A: 

First, why 3 tables all with 1:1 relationships? A 2NF-compliant single table should work considerably better.

But if you still want 3 tables, try relating crm_contact_informations to crms, not to screens:

id = Column("id", Integer, ForeignKey("crms.id"), primary_key=True)
Hollister