Em Terça 23 Maio 2006 11:48, Javier Rojas escreveu:
> Hi,
>
> I'll better start with an example. I have two tables, patients and
> symptoms, and I have too a table patient-symptom, on which every row
> means that a patient has a particular symptom. I know I can represent
> that with RelatedJoin(s). My problem is that, besides associating a
> symptom to a patient, I need to keep some annotations about every
> patient-symptom entry, something like this
>
> Patient
> # pat_ID
>
> Symptom
> # symp_ID
>
> Patient-Symptom
> # pat_ID
> # symp_ID
> * Annotation
>
> And I don't know how to represent that with SQLObject
>
> Any help would be really appreciated.

I'd go this way:

        - 3 classes
                - Patient
                        - patient data
                - Sympton
                        - sympton data
                - PatientSympton
                        - patient  (if this is a ForeignKey, SO will create 
patient_id in your 
                                    database and also a patientID column on 
your model)
                        - sympton  (same as above comment)
                        - annotation
                        - extra columns

Then, I'd declare on the join that I wat to use patient_id and sympton_id on 
PatientSympton as joining columns.  Extra information can be filled directly 
on PatientSympton.

You have to create the class manually to use this extra column.  (Actually, I 
haven't tried, but I remember that there's an add_column or something like 
that method...  But you'll have to instantiate the intermediate table anyway, 
so I believe it is better to have everything there...)

In SQLObject terms it would be along the lines of:


class Patient(SQLObject):
    class sqlmeta:
        table = "optional_schema.patient"

    name = UnicodeCol(notNone = True)
    # ...

class Sympton(SQLObject):
    class sqlmeta:
        table = "sympton"

    description = UnicodeCol(notNone = True)
    # ...

class PatientSympton(SQLObject):
    class sqlmeta:
        table = "patients_symptons"

    patient = ForeignKey('Patient', notNone = True)
    sympton = ForeignKey('Sympton', notNone = True)
    annotation = UnicodeCol(notNone = False)

    # If you won't have repeated entries here, you can create a UNIQUE index: 
    idxPatientSympton = DatabaseIndex('patient', 'sympton', unique = True)



-- 
Jorge Godoy      <[EMAIL PROTECTED]>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to