oh, ok.  Here's a simplified case:

from sqlalchemy import *
from sqlalchemy.orm import *

engine = create_engine('sqlite:///:memory:', echo=False)
Session = sessionmaker(bind=engine)
session = Session()
metadata = MetaData()

# this table contains the base data for a patient, like his name,
phone number ...
patient_table = Table('patient', metadata,
                                Column('patID', Integer, primary_key=True, 
nullable = False),
                                Column('name', String),
                                )

# Stores data like which operations have been performed on a patient
or which exams have been performed ...
patientChart_table = Table('patientChart', metadata,
                                Column('id', Integer, primary_key=True, 
nullable = False),
                                Column('parent', Integer, 
ForeignKey('patientChart.id')),
                                Column('type', String),
                                Column('patID', Integer, 
ForeignKey('patient.patID'), nullable =
False),
                                )

metadata.create_all(engine)

class patient(object):
  pass

class chartItem(object):
        pass

mapper(chartItem, patientChart_table,
        properties={
        'children': relation(chartItem)
        })

mapper(patient, patient_table, properties={
        'chart': relation(chartItem)
        })

testpat = patient()
testpat.name = "Test Patient"

session.add(testpat)
testpat.chart.append(chartItem())
testpat.chart.append(chartItem())

session.commit()
print testpat.chart[0].id, testpat.chart[0].patID
print testpat.chart[1].id, testpat.chart[1].patID

c = chartItem()

# there is no cascade from "patient" to the children of "chartItem"
c.patID = testpat.chart[0].patID
testpat.chart[0].children.append(c)
session.commit()

There is no cascade of patient's "patID" column to objects that are
attached to its child "chart" objects, it only deals with the relation
to the chart items that are immediately associated with it.   You'd
have to do that manually or add a before_save() hook to populate it.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to