RE: Re: Help with record definition
"Berglas, Anthony" <[email protected]>
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Message-ID | <[email protected]> |
John, Please include the code that is causing you the issue in a message. But first look at the Employee/Department example. Note that Employee just references Department, and the Department Id field is automatically included in the Employee record. If Department had a two column key, then both columns would automatically be included. The payroll example is more complex. Framk, As a separate exercise, it would be great to have an example of what this would look like in your branch. [Be very clear which branch you are talking about.] Thanks, Anthony > -----Original Message----- > From: [email protected] [mailto:[email protected]] On > Behalf Of john_price_137 > Sent: Thursday, March 15, 2007 9:44 AM > To: [email protected] > Subject: [SimpleORM] Re: Help with record definition > > Hi, > Thanks for the reply. Thats what I tried first, but I get a > "Duplicate Column Name" error for ROLE_ID and USER_NAME. > > The problem is their are only two fields in the table, both > of which make up the primary key, and each field is also > a foreign key to another table. > > John > > > --- In [email protected], Franck Routier <franck.routier@...> > wrote: > > > > Hi, > > > > sure, it is the very purpose of SFieldReference. > > > > you should just add the following fields to you UserRole class : > > > > public static final SFieldReference ROLE = > > new SFieldReference(meta, Role.meta) > > > > public static final SFieldReference USER = > > new SFieldReference(meta, User.meta) > > > > (provided that you defined a Role and User class representing these > tables). > > > > This very straightforward constructor works if the name of the > fields in > > both tables are the same, which seems to be your case ! > > > > You then can use SRecordInstance.getReference(UserRole.USER) to access > > the referenced user.... > > > > Does it help ? > > > > Franck > > > > > > john_price_137 a écrit : > > > > > > Help, I have a table with the following definition: > > > > > > CREATE TABLE USER_ROLES ( > > > USER_NAME VARCHAR(20) NOT NULL, > > > ROLE_ID INTEGER NOT NULL > > > ); > > > > > > PRIMARY KEY (USER_NAME, ROLE_ID); > > > FOREIGN KEY (USER_NAME) REFERENCES USERS (USER_NAME); > > > FOREIGN KEY (ROLE_ID) REFERENCES "ROLE" (ROLE_ID); > > > > > > and have defined a class for it as: > > > > > > public class UserRole extends SRecordInstance > > > { > > > public static final SRecordMeta meta = new > > > RecordMeta(UserRole.class, "USER_ROLES"); > > > > > > public static final SFieldString USER_NAME = new > > > SFieldString(meta, "USER_NAME", 20, SCon.SFD_PRIMARY_KEY); > > > > > > public static final SFieldLong ROLE_ID = new SFieldLong(meta, > > > "ROLE_ID", SCon.SFD_PRIMARY_KEY); > > > } > > > > > > is it possible to define references to the USERS and ROLE tables ? > > > and how do I do it! > > > > > > > > > > > > > > > Yahoo! Groups Links > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> Yahoo! Groups gets a make over. See the new email design. http://us.click.yahoo.com/hOt0.A/lOaOAA/yQLSAA/5cFolB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/SimpleORM/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/SimpleORM/join (Yahoo! ID required) <*> To change settings via email: mailto:[email protected] mailto:[email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/