I have a data graph mapped as:
class BatchDetail(BASE):
__tablename__ = TABLE_BATCH_DET
id = Column(Integer, primary_key=True)
batch = Column(ForeignKey(TABLE_BATCH_HDR + '.id'))
account_id = Column(ForeignKey(TABLE_L3_ACCT + '.id'))
# other fields
# -----------------------------
class BatchHeader(BASE):
__tablename__ = TABLE_BATCH_HDR
id = Column(Integer, primary_key=True)
# other fields
detail = relation('BatchDetail',
backref=backref('header', remote_side=id))
# ---------------------------
class L3Acct(BASE):
__tablename__ = TABLE_L3_ACCT
__table_args__ = (UniqueConstraint("l2_id", "l3_acct"), {})
id = Column(Integer, primary_key=True)
parent = Column(ForeignKey(TABLE_L3_ACCT + '.id'))
l2_id = Column(ForeignKey(TABLE_L2_ACCT + '.id'))
# other fields
Basically, a 'batch' consists of a number of detail lines, each of which has an
associated L3Account. In addition, each L3Acct is a child of a L2Acct (l2_id
foreign key) and may be a child of another L3Acct (parent foreign key).
The application considers the 'batch' (BatchHeader) as the main item. A batch
is created and detail (BatchDetail) rows are added. The L3Acct is used as a
lookup. In my mapping, I haven't set up a relationship between BatchDetail and
L3Acct and I'm maintaining that relationship with code external to the mapping.
Is it possible to let SA manage this relationship?
if so, Here's what I'm having trouble with. When the application needs to add
a new detail record, it can just create a new BatchDetail instance and append
it to the detail collection. I assume that similarly, to associate a L3Acct,
the BatchDetail instance needs to be added to a collection associated with
L3Acct, but where is that collection? And how would one change the association
from one L3Acct to another? Maybe a better way of asking this question is how
to you work with a one-many relationship from the 'many' side?
Thanks,
Mark
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.