Glorp - Relationship Mapping between 2 different data types

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Glorp - Relationship Mapping between 2 different data types

Brett Taylor
I have a 1 to many relationship between 2 classes that I need to map.  The underlying tables are from 2 separate systems which I have no control over.  

The classes are: PatientVisit  and DocumentReference
PatientVisit maps directly to table PATIENT_MASTER and DocumenReference maps to table DOCUMENT
PatientVisit has an instance variable named "documents" that should contain a collection of DocumentReference instances (This is the 1 to many relationship).

The PATIENT_MASTER table has a primary key field defined as :
PATIENT_NO  decimal(10,0);
(e.g. 792345)
 
The DOCUMENT table has a foreign key field  defined as:
PATIENT_ACCT char(10);
(e.g. '0000792345')  PATIENT_ACCT is padded with leading zero's.

I would like to map PATIENT_NO to PATIENT_ACCT but I am not sure how to do this with GLORP.  Can someone give me a hint?
Thanks,
Brett

Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Glorp - Relationship Mapping between 2 different data types

Alan Knight-2
Ugh.  Well, if your database is forgiving enough, you may be able to just map the fields together and have it work. But since you're asking the question, I'm guessing that your database isn't that forgiving.

So I think that what you'd need to do is describe the join using a conversion function on one of them. A number of conversion functions might work, cast is the most standard. So what you might try doing is looking at the method asDate in ObjectExpression and writing an analogous asString method. Then you could do
   target := [:each | ((each getTable: patientMasterTable) getField: (patientMasterTable fieldNamed: 'PATIENT_NO'))) asString] asGlorpExpression.
   ...
   Join
      from: (documentTable fieldNamed: 'PATIENT_ACCT')
      to: target

At 05:13 PM 12/27/2008, Brett Taylor wrote:

I have a 1 to many relationship between 2 classes that I need to map.  The
underlying tables are from 2 separate systems which I have no control over. 

The classes are: PatientVisit  and DocumentReference
PatientVisit maps directly to table PATIENT_MASTER and DocumenReference maps
to table DOCUMENT
PatientVisit has an instance variable named "documents" that should contain
a collection of DocumentReference instances (This is the 1 to many
relationship).

The PATIENT_MASTER table has a primary key field defined as :
PATIENT_NO  decimal(10,0);
(e.g. 792345)
 
The DOCUMENT table has a foreign key field  defined as:
PATIENT_ACCT char(10);
(e.g. '0000792345')  PATIENT_ACCT is padded with leading zero's.

I would like to map PATIENT_NO to PATIENT_ACCT but I am not sure how to do
this with GLORP.  Can someone give me a hint?
Thanks,
Brett


--
View this message in context: http://www.nabble.com/Glorp---Relationship-Mapping-between-2-different-data-types-tp21188156p21188156.html
Sent from the VisualWorks mailing list archive at Nabble.com.

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

--
Alan Knight [|], Engineering Manager, Cincom Smalltalk

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc