Hello all,
It seems like I can't go a day without running into some kind of wall.
This one is a conceptual one regarding foreign keys. I have to somehow
get the same FK column in table A pointing to IDs in tables B and C.

At one person's suggestion, I'm making classes for my tables, even
though I'm using automap. This is to let me stop doing a ton of joins,
making querying much easier... I hope! I'm defining all the foreign
keys between my tables manually. For instance:

class item(base):
 __tablename__ = "item"
 itm_id = Column(Integer, primary_key=True)
 vendornum = Column(String, ForeignKey(VENDR.PVVNNO))

class vendorTable(base):
 __tablename__ = "VENDR"
 PVVNNO = Column(String, primary_key=True)

If I've understood correctly, I'll now be able to say
item.vendornum.vendor_full_name
to get the vendor's full name for any item.

Here's the problem. Items have attachments, and attached text,
respectively held in attach and attach_text tables. Binding them to
items is a table called assignment. Assignment is pretty
straightforward, with an itm_id and an attachment id (att_id). The
trouble is that this att_id occurs in both attach and attach_text. I
can make att_id a foreign key to one table or the other, but I'm not
sure how to make it go to both tables.

class assignmentTable(base):
 __tablename__ = "assignment"
 itm_id = Column(Integer, ForeignKey(item.itm_id))
 #the following column has to point to attach_text.att_id AS WELL
  att_id = Column(Integer, ForeignKey(attachment.att_id))
 seq_num = Column(Integer)
 asn_primary = Column(Integer, nullable=True)

class attachmentTable(base):
 __tablename__ = "attachment"
 att_id = Column(Integer, primary_key=True)

class attachmentTextTable(base):
 __tablename__ = "attach_text"
 att_id = Column(Integer, primary_key=True)

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to